Whamcloud - gitweb
b=15534
authorpravins <pravins>
Tue, 15 Sep 2009 11:09:56 +0000 (11:09 +0000)
committerpravins <pravins>
Tue, 15 Sep 2009 11:09:56 +0000 (11:09 +0000)
i=tappro
i=eric.mei
ppc64 support

25 files changed:
lustre/include/lustre/lustre_idl.h
lustre/include/lustre_capa.h
lustre/include/lustre_dlm.h
lustre/include/lustre_net.h
lustre/include/lustre_req_layout.h
lustre/include/lustre_sec.h
lustre/include/obd.h
lustre/ldlm/ldlm_lockd.c
lustre/mdc/mdc_request.c
lustre/mdt/mdt_handler.c
lustre/obdfilter/filter_lvb.c
lustre/osc/osc_request.c
lustre/ost/ost_handler.c
lustre/ptlrpc/client.c
lustre/ptlrpc/gss/gss_cli_upcall.c
lustre/ptlrpc/gss/gss_internal.h
lustre/ptlrpc/gss/sec_gss.c
lustre/ptlrpc/layout.c
lustre/ptlrpc/pack_generic.c
lustre/ptlrpc/ptlrpc_module.c
lustre/ptlrpc/sec.c
lustre/ptlrpc/sec_bulk.c
lustre/ptlrpc/sec_null.c
lustre/ptlrpc/sec_plain.c
lustre/ptlrpc/service.c

index c36d35a..c0978d4 100644 (file)
@@ -680,6 +680,9 @@ extern void lustre_swab_ptlrpc_body(struct ptlrpc_body *pb);
 #define DLM_LOCKREPLY_OFF               1 /* lockrep offset */
 #define DLM_REPLY_REC_OFF               2 /* reply record offset */
 
+/** only use in req->rq_{req,rep}_swab_mask */
+#define MSG_PTLRPC_HEADER_OFF           31
+
 /* Flags that are operation-specific go in the top 16 bits. */
 #define MSG_OP_FLAG_MASK   0xffff0000
 #define MSG_OP_FLAG_SHIFT  16
index 4e12392..9b9b21b 100644 (file)
@@ -285,17 +285,17 @@ static inline int capa_opc_supported(struct lustre_capa *capa, __u64 opc)
 }
 
 static inline struct lustre_capa *
-lustre_unpack_capa(struct lustre_msg *msg, unsigned int offset)
+lustre_unpack_incoming_capa(struct ptlrpc_request *req, unsigned int offset)
 {
         struct lustre_capa *capa;
 
-        capa = lustre_swab_buf(msg, offset, sizeof(*capa),
-                               lustre_swab_lustre_capa);
+        capa = lustre_swab_reqbuf(req, offset, sizeof(*capa),
+                                  lustre_swab_lustre_capa);
         if (capa == NULL)
                 CERROR("bufcount %u, bufsize %u\n",
-                       lustre_msg_bufcount(msg),
-                       (lustre_msg_bufcount(msg) <= offset) ?
-                                -1 : lustre_msg_buflen(msg, offset));
+                       lustre_msg_bufcount(req->rq_reqmsg),
+                       (lustre_msg_bufcount(req->rq_reqmsg) <= offset) ?
+                                -1 : lustre_msg_buflen(req->rq_reqmsg, offset));
 
         return capa;
 }
index c4ec9da..13794ac 100644 (file)
@@ -367,7 +367,8 @@ typedef int (*ldlm_res_policy)(struct ldlm_namespace *, struct ldlm_lock **,
 
 struct ldlm_valblock_ops {
         int (*lvbo_init)(struct ldlm_resource *res);
-        int (*lvbo_update)(struct ldlm_resource *res, struct lustre_msg *m,
+        int (*lvbo_update)(struct ldlm_resource *res,
+                           struct ptlrpc_request *r,
                            int buf_idx, int increase);
 };
 
@@ -899,12 +900,12 @@ ldlm_handle2lock_long(const struct lustre_handle *h, int flags)
 }
 
 static inline int ldlm_res_lvbo_update(struct ldlm_resource *res,
-                                       struct lustre_msg *m, int buf_idx,
+                                       struct ptlrpc_request *r, int buf_idx,
                                        int increase)
 {
         if (res->lr_namespace->ns_lvbo &&
             res->lr_namespace->ns_lvbo->lvbo_update) {
-                return res->lr_namespace->ns_lvbo->lvbo_update(res, m, buf_idx,
+                return res->lr_namespace->ns_lvbo->lvbo_update(res, r, buf_idx,
                                                                increase);
         }
         return 0;
index 57463eb..5335daf 100644 (file)
@@ -509,30 +509,40 @@ static inline int ptlrpc_req_interpret(const struct lu_env *env,
         return rc;
 }
 
-static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
+static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
 {
         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
-        LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
-        req->rq_req_swab_mask |= 1 << index;
+        return req->rq_req_swab_mask & (1 << index);
 }
 
-static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
+static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
 {
         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
-        LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
-        req->rq_rep_swab_mask |= 1 << index;
+        return req->rq_rep_swab_mask & (1 << index);
 }
 
-static inline int lustre_req_swabbed(struct ptlrpc_request *req, int index)
+static inline int ptlrpc_req_need_swab(struct ptlrpc_request *req)
+{
+        return lustre_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+}
+
+static inline int ptlrpc_rep_need_swab(struct ptlrpc_request *req)
+{
+        return lustre_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+}
+
+static inline void lustre_set_req_swabbed(struct ptlrpc_request *req, int index)
 {
         LASSERT(index < sizeof(req->rq_req_swab_mask) * 8);
-        return req->rq_req_swab_mask & (1 << index);
+        LASSERT((req->rq_req_swab_mask & (1 << index)) == 0);
+        req->rq_req_swab_mask |= 1 << index;
 }
 
-static inline int lustre_rep_swabbed(struct ptlrpc_request *req, int index)
+static inline void lustre_set_rep_swabbed(struct ptlrpc_request *req, int index)
 {
         LASSERT(index < sizeof(req->rq_rep_swab_mask) * 8);
-        return req->rq_rep_swab_mask & (1 << index);
+        LASSERT((req->rq_rep_swab_mask & (1 << index)) == 0);
+        req->rq_rep_swab_mask |= 1 << index;
 }
 
 static inline const char *
@@ -1079,7 +1089,15 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
 
 /* ptlrpc/pack_generic.c */
 int ptlrpc_reconnect_import(struct obd_import *imp);
-int lustre_msg_swabbed(struct lustre_msg *msg);
+
+/** ptlrpc mgs buffer swab interface */
+int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
+                         int index);
+void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
+                                int index);
+int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
+int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
+
 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
                         char **bufs);
@@ -1095,19 +1113,18 @@ int lustre_pack_reply_flags(struct ptlrpc_request *, int count, __u32 *lens,
 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
                       unsigned int newlen, int move_data);
 void lustre_free_reply_state(struct ptlrpc_reply_state *rs);
+int __lustre_unpack_msg(struct lustre_msg *m, int len);
 int lustre_msg_hdr_size(__u32 magic, int count);
 int lustre_msg_size(__u32 magic, int count, __u32 *lengths);
 int lustre_msg_size_v2(int count, __u32 *lengths);
 int lustre_packed_msg_size(struct lustre_msg *msg);
 int lustre_msg_early_size(void);
-int lustre_unpack_msg(struct lustre_msg *m, int len);
 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
 int lustre_msg_buflen(struct lustre_msg *m, int n);
 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
 int lustre_msg_bufcount(struct lustre_msg *m);
 char *lustre_msg_string (struct lustre_msg *m, int n, int max_len);
-void *lustre_swab_buf(struct lustre_msg *, int n, int minlen, void *swabber);
 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int n, int minlen,
                          void *swabber);
 void *lustre_swab_repbuf(struct ptlrpc_request *req, int n, int minlen,
index 369cfe6..e90f554 100644 (file)
@@ -61,7 +61,6 @@ enum req_location {
 struct req_capsule {
         struct ptlrpc_request   *rc_req;
         const struct req_format *rc_fmt;
-        __u32                    rc_swabbed;
         enum req_location        rc_loc;
         __u32                    rc_area[RCL_NR][REQ_MAX_FIELD_NR];
 };
index 3fdf2e7..1866a46 100644 (file)
@@ -795,7 +795,7 @@ int sptlrpc_svc_unwrap_bulk(struct ptlrpc_request *req,
 int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg,
                               void *buf, int buflen);
 
-int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset);
+int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset, int swabbed);
 
 /* user descriptor helpers */
 static inline int sptlrpc_user_desc_size(int ngroups)
@@ -805,7 +805,7 @@ static inline int sptlrpc_user_desc_size(int ngroups)
 
 int sptlrpc_current_user_desc_size(void);
 int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset);
-int sptlrpc_unpack_user_desc(struct lustre_msg *msg, int offset);
+int sptlrpc_unpack_user_desc(struct lustre_msg *req, int offset, int swabbed);
 
 
 #define CFS_CAP_CHOWN_MASK (1 << CFS_CAP_CHOWN)
index 9eb9c76..6c28088 100644 (file)
@@ -1623,7 +1623,7 @@ static inline const struct lsm_operations *lsm_op_find(int magic)
         case LOV_MAGIC_V3:
                return &lsm_v3_ops;
         default:
-               CERROR("Cannot recognize lsm_magic %d\n", magic);
+               CERROR("Cannot recognize lsm_magic %08x\n", magic);
                return NULL;
         }
 }
index 76f2923..26dfc80 100644 (file)
@@ -949,8 +949,8 @@ int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data)
         else if (rc != 0)
                 rc = ldlm_handle_ast_error(lock, req, rc, "glimpse");
         else
-                rc = ldlm_res_lvbo_update(res, req->rq_repmsg,
-                                          REPLY_REC_OFF, 1);
+                rc = ldlm_res_lvbo_update(res, req, REPLY_REC_OFF, 1);
+
         ptlrpc_req_finished(req);
         if (rc == -ERESTART)
                 ldlm_reprocess_all(res);
index db1dc06..963efd4 100644 (file)
@@ -1139,7 +1139,7 @@ int mdc_get_info_rpc(struct obd_export *exp,
         if (rc == 0) {
                 tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL);
                 memcpy(val, tmp, vallen);
-                if (lustre_msg_swabbed(req->rq_repmsg)) {
+                if (ptlrpc_rep_need_swab(req)) {
                         if (KEY_IS(KEY_FID2PATH)) {
                                 lustre_swab_fid2path(val);
                         }
index fbaf0fe..383ab8a 100644 (file)
@@ -1124,7 +1124,7 @@ static int mdt_set_info(struct mdt_thread_info *info)
                         CERROR("Bad changelog_clear setinfo size %d\n", vallen);
                         RETURN(-EINVAL);
                 }
-                if (lustre_msg_swabbed(req->rq_reqmsg)) {
+                if (ptlrpc_req_need_swab(req)) {
                         __swab64s(&cs->cs_recno);
                         __swab32s(&cs->cs_id);
                 }
@@ -2919,15 +2919,6 @@ static int mdt_handle0(struct ptlrpc_request *req,
         if (likely(rc == 0)) {
                 rc = mdt_recovery(info);
                 if (likely(rc == +1)) {
-                        switch (lustre_msg_get_opc(msg)) {
-                        case MDS_READPAGE:
-                                req->rq_bulk_read = 1;
-                                break;
-                        case MDS_WRITEPAGE:
-                                req->rq_bulk_write = 1;
-                                break;
-                        }
-
                         h = mdt_handler_find(lustre_msg_get_opc(msg),
                                              supported);
                         if (likely(h != NULL)) {
@@ -5373,7 +5364,7 @@ static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
         fpin = key + size_round(sizeof(KEY_FID2PATH));
         fpout = val;
 
-        if (lustre_msg_swabbed(mdt_info_req(info)->rq_reqmsg))
+        if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
                 lustre_swab_fid2path(fpin);
 
         memcpy(fpout, fpin, sizeof(*fpin));
index eed2a34..1f627b2 100644 (file)
@@ -120,7 +120,8 @@ out_dentry:
  *
  *   If 'increase_only' is true, don't allow values to move backwards.
  */
-static int filter_lvbo_update(struct ldlm_resource *res, struct lustre_msg *m,
+static int filter_lvbo_update(struct ldlm_resource *res,
+                              struct ptlrpc_request *r,
                               int buf_idx, int increase_only)
 {
         int rc = 0;
@@ -139,11 +140,13 @@ static int filter_lvbo_update(struct ldlm_resource *res, struct lustre_msg *m,
         }
 
         /* Update the LVB from the network message */
-        if (m != NULL) {
+        if (r != NULL) {
                 struct ost_lvb *new;
 
-                new = lustre_swab_buf(m, buf_idx, sizeof(*new),
-                                      lustre_swab_ost_lvb);
+                /* XXX update always from reply buffer */
+                new = lustre_swab_repbuf(r, buf_idx, sizeof(*new),
+                                         lustre_swab_ost_lvb);
+
                 if (new == NULL) {
                         CERROR("lustre_swab_buf failed\n");
                         goto disk_update;
index b9174c8..3875089 100644 (file)
@@ -1138,7 +1138,7 @@ static int check_write_rcs(struct ptlrpc_request *req,
                 CDEBUG(D_INFO, "Missing/short RC vector on BRW_WRITE reply\n");
                 return(-EPROTO);
         }
-        if (lustre_msg_swabbed(req->rq_repmsg))
+        if (ptlrpc_rep_need_swab(req))
                 for (i = 0; i < niocount; i++)
                         __swab32s(&remote_rcs[i]);
 
index 02298d1..3f0da6c 100644 (file)
@@ -129,7 +129,7 @@ static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
         }
 
         if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
-                capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 2);
+                capa = lustre_unpack_incoming_capa(req, REQ_REC_OFF + 2);
 
         rc = lustre_pack_reply(req, 2, size, NULL);
         if (rc)
@@ -167,7 +167,7 @@ static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
 
         oinfo.oi_oa = &repbody->oa;
         if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
-                oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
+                oinfo.oi_capa = lustre_unpack_incoming_capa(req,
                                                    REQ_REC_OFF + 1);
         req->rq_status = obd_getattr(exp, &oinfo);
         ost_drop_id(exp, &repbody->oa);
@@ -331,7 +331,7 @@ static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
                         oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
 
                 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
-                        oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
+                        oinfo.oi_capa = lustre_unpack_incoming_capa(req,
                                                            REQ_REC_OFF + 1);
                 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
                 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
@@ -355,7 +355,7 @@ static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
                 RETURN(-EFAULT);
 
         if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
-                capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
+                capa = lustre_unpack_incoming_capa(req, REQ_REC_OFF + 1);
 
         rc = lustre_pack_reply(req, 2, size, NULL);
         if (rc)
@@ -394,7 +394,7 @@ static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
 
         oinfo.oi_oa = &repbody->oa;
         if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
-                oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
+                oinfo.oi_capa = lustre_unpack_incoming_capa(req,
                                                    REQ_REC_OFF + 1);
         req->rq_status = obd_setattr(exp, &oinfo, oti);
         ost_drop_id(exp, &repbody->oa);
@@ -656,7 +656,7 @@ static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
         LASSERT(remote_nb != NULL);
 
         if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
-                capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
+                capa = lustre_unpack_incoming_capa(req, REQ_REC_OFF + 3);
 
         rc = lustre_pack_reply(req, 2, size, NULL);
         if (rc)
@@ -921,7 +921,7 @@ static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
         LASSERT(remote_nb != NULL);
 
         if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
-                capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
+                capa = lustre_unpack_incoming_capa(req, REQ_REC_OFF + 3);
 
         size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
         rc = lustre_pack_reply(req, 3, size, NULL);
@@ -1223,7 +1223,7 @@ static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
                 if (val && vallen)
                         obd_export_evict_by_nid(exp->exp_obd, val);
                 GOTO(out, rc = 0);
-        } else if (KEY_IS(KEY_MDS_CONN) && lustre_msg_swabbed(req->rq_reqmsg)) {
+        } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
                 /* Val's are not swabbed automatically */
                 __swab32s((__u32 *)val);
         }
@@ -1819,8 +1819,6 @@ static int ost_hpreq_handler(struct ptlrpc_request *req)
                                 RETURN(-EFAULT);
                         }
 
-                        swab = !lustre_req_swabbed(req, REQ_REC_OFF + 1) &&
-                                lustre_msg_swabbed(req->rq_reqmsg);
                         ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
                                                  objcount * sizeof(*ioo),
                                                  lustre_swab_obd_ioobj);
@@ -1828,6 +1826,8 @@ static int ost_hpreq_handler(struct ptlrpc_request *req)
                                 CERROR("Missing/short ioobj\n");
                                 RETURN(-EFAULT);
                         }
+
+                        swab = ptlrpc_req_need_swab(req);
                         for (niocount = i = 0; i < objcount; i++) {
                                 if (i > 0 && swab)
                                         lustre_swab_obd_ioobj(&ioo[i]);
@@ -1843,8 +1843,6 @@ static int ost_hpreq_handler(struct ptlrpc_request *req)
                                 RETURN(-EFAULT);
                         }
 
-                        swab = !lustre_req_swabbed(req, REQ_REC_OFF + 2) &&
-                                lustre_msg_swabbed(req->rq_reqmsg);
                         nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
                                                 niocount * sizeof(*nb),
                                                 lustre_swab_niobuf_remote);
@@ -1853,6 +1851,7 @@ static int ost_hpreq_handler(struct ptlrpc_request *req)
                                 RETURN(-EFAULT);
                         }
 
+                        swab = ptlrpc_req_need_swab(req);
                         if (swab) {
                                 /* swab remaining niobufs */
                                 for (i = 1; i < niocount; i++)
index 40500cf..3176dda 100644 (file)
@@ -281,13 +281,12 @@ static int unpack_reply(struct ptlrpc_request *req)
 {
         int rc;
 
-        /* Clear reply swab mask; we may have already swabbed an early reply */
-        req->rq_rep_swab_mask = 0;
-
-        rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
-        if (rc) {
-                DEBUG_REQ(D_ERROR, req, "unpack_rep failed: %d", rc);
-                return(-EPROTO);
+        if (SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) != SPTLRPC_POLICY_NULL) {
+                rc = ptlrpc_unpack_rep_msg(req, req->rq_replen);
+                if (rc) {
+                        DEBUG_REQ(D_ERROR, req, "unpack_rep failed: %d", rc);
+                        return(-EPROTO);
+                }
         }
 
         rc = lustre_unpack_rep_ptlrpc_body(req, MSG_PTLRPC_BODY_OFF);
index bec0316..370004c 100644 (file)
@@ -150,7 +150,7 @@ int ctx_init_pack_request(struct obd_import *imp,
 }
 
 static
-int ctx_init_parse_reply(struct lustre_msg *msg,
+int ctx_init_parse_reply(struct lustre_msg *msg, int swabbed,
                          char __user *outbuf, long outlen)
 {
         struct gss_rep_header   *ghdr;
@@ -162,7 +162,7 @@ int ctx_init_parse_reply(struct lustre_msg *msg,
                 return -EPROTO;
         }
 
-        ghdr = (struct gss_rep_header *) gss_swab_header(msg, 0);
+        ghdr = (struct gss_rep_header *) gss_swab_header(msg, 0, swabbed);
         if (ghdr == NULL) {
                 CERROR("unable to extract gss reply header\n");
                 return -EPROTO;
@@ -356,6 +356,7 @@ int gss_do_ctx_init_rpc(__user char *buffer, unsigned long count)
 
         LASSERT(req->rq_repdata);
         lsize = ctx_init_parse_reply(req->rq_repdata,
+                                     ptlrpc_rep_need_swab(req),
                                      param.reply_buf, param.reply_buf_size);
         if (lsize < 0) {
                 param.status = (int) lsize;
index 66afd61..e09f444 100644 (file)
@@ -400,7 +400,8 @@ int cli_ctx_check_death(struct ptlrpc_cli_ctx *ctx);
 int gss_copy_rvc_cli_ctx(struct ptlrpc_cli_ctx *cli_ctx,
                          struct ptlrpc_svc_ctx *svc_ctx);
 
-struct gss_header *gss_swab_header(struct lustre_msg *msg, int segment);
+struct gss_header *gss_swab_header(struct lustre_msg *msg, int segment,
+                                   int swabbed);
 netobj_t *gss_swab_netobj(struct lustre_msg *msg, int segment);
 
 void gss_cli_ctx_uptodate(struct gss_cli_ctx *gctx);
index 1556e58..a6e5fbe 100644 (file)
@@ -111,17 +111,21 @@ void gss_header_swabber(struct gss_header *ghdr)
         __swab32s(&ghdr->gh_handle.len);
 }
 
-struct gss_header *gss_swab_header(struct lustre_msg *msg, int segment)
+struct gss_header *gss_swab_header(struct lustre_msg *msg, int segment,
+                                   int swabbed)
 {
         struct gss_header *ghdr;
 
-        ghdr = lustre_swab_buf(msg, segment, sizeof(*ghdr),
-                               gss_header_swabber);
+        ghdr = lustre_msg_buf(msg, segment, sizeof(*ghdr));
+        if (ghdr == NULL)
+                return NULL;
+
+        if (swabbed)
+                gss_header_swabber(ghdr);
 
-        if (ghdr &&
-            sizeof(*ghdr) + ghdr->gh_handle.len > msg->lm_buflens[segment]) {
-                CERROR("gss header require length %u, now %u received\n",
-                       (unsigned int) sizeof(*ghdr) + ghdr->gh_handle.len,
+        if (sizeof(*ghdr) + ghdr->gh_handle.len > msg->lm_buflens[segment]) {
+                CERROR("gss header has length %d, now %u received\n",
+                       (int) sizeof(*ghdr) + ghdr->gh_handle.len,
                        msg->lm_buflens[segment]);
                 return NULL;
         }
@@ -129,6 +133,7 @@ struct gss_header *gss_swab_header(struct lustre_msg *msg, int segment)
         return ghdr;
 }
 
+#if 0
 static
 void gss_netobj_swabber(netobj_t *obj)
 {
@@ -149,6 +154,7 @@ netobj_t *gss_swab_netobj(struct lustre_msg *msg, int segment)
 
         return obj;
 }
+#endif
 
 /*
  * payload should be obtained from mechanism. but currently since we
@@ -765,7 +771,7 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
         struct gss_header      *ghdr, *reqhdr;
         struct lustre_msg      *msg = req->rq_repdata;
         __u32                   major;
-        int                     pack_bulk, rc = 0;
+        int                     pack_bulk, swabbed, rc = 0;
         ENTRY;
 
         LASSERT(req->rq_cli_ctx == ctx);
@@ -786,7 +792,9 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
                 RETURN(-EPROTO);
         }
 
-        ghdr = gss_swab_header(msg, 0);
+        swabbed = ptlrpc_rep_need_swab(req);
+
+        ghdr = gss_swab_header(msg, 0, swabbed);
         if (ghdr == NULL) {
                 CERROR("can't decode gss header\n");
                 RETURN(-EPROTO);
@@ -824,7 +832,7 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
                         RETURN(-EPROTO);
                 }
 
-                if (lustre_msg_swabbed(msg))
+                if (swabbed)
                         gss_header_swabber(ghdr);
 
                 major = gss_verify_msg(msg, gctx->gc_mechctx, reqhdr->gh_svc);
@@ -854,7 +862,7 @@ int gss_cli_ctx_verify(struct ptlrpc_cli_ctx *ctx,
                                 RETURN(-EPROTO);
                         }
 
-                        rc = bulk_sec_desc_unpack(msg, 2);
+                        rc = bulk_sec_desc_unpack(msg, 2, swabbed);
                         if (rc) {
                                 CERROR("unpack bulk desc: %d\n", rc);
                                 RETURN(rc);
@@ -985,7 +993,7 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
         struct gss_cli_ctx      *gctx;
         struct gss_header       *ghdr;
         struct lustre_msg       *msg = req->rq_repdata;
-        int                      msglen, pack_bulk, rc;
+        int                      msglen, pack_bulk, swabbed, rc;
         __u32                    major;
         ENTRY;
 
@@ -994,8 +1002,9 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
         LASSERT(msg);
 
         gctx = container_of(ctx, struct gss_cli_ctx, gc_base);
+        swabbed = ptlrpc_rep_need_swab(req);
 
-        ghdr = gss_swab_header(msg, 0);
+        ghdr = gss_swab_header(msg, 0, swabbed);
         if (ghdr == NULL) {
                 CERROR("can't decode gss header\n");
                 RETURN(-EPROTO);
@@ -1018,7 +1027,7 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
                         RETURN(-EPROTO);
                 }
 
-                if (lustre_msg_swabbed(msg))
+                if (swabbed)
                         gss_header_swabber(ghdr);
 
                 /* use rq_repdata_len as buffer size, which assume unseal
@@ -1033,7 +1042,8 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
                         break;
                 }
 
-                if (lustre_unpack_msg(msg, msglen)) {
+                swabbed = __lustre_unpack_msg(msg, msglen);
+                if (swabbed < 0) {
                         CERROR("Failed to unpack after decryption\n");
                         RETURN(-EPROTO);
                 }
@@ -1051,7 +1061,8 @@ int gss_cli_ctx_unseal(struct ptlrpc_cli_ctx *ctx,
                         }
 
                         /* bulk checksum is the last segment */
-                        if (bulk_sec_desc_unpack(msg, msg->lm_bufcount - 1))
+                        if (bulk_sec_desc_unpack(msg, msg->lm_bufcount - 1,
+                                                 swabbed))
                                 RETURN(-EPROTO);
                 }
 
@@ -1975,7 +1986,7 @@ int gss_svc_handle_init(struct ptlrpc_request *req,
         rawobj_t                   uuid_obj, rvs_hdl, in_token;
         __u32                      lustre_svc;
         __u32                     *secdata, seclen;
-        int                        rc;
+        int                        swabbed, rc;
         ENTRY;
 
         CDEBUG(D_SEC, "processing gss init(%d) request from %s\n", gw->gw_proc,
@@ -1999,6 +2010,8 @@ int gss_svc_handle_init(struct ptlrpc_request *req,
                 RETURN(SECSVC_DROP);
         }
 
+        swabbed = ptlrpc_req_need_swab(req);
+
         /* ctx initiate payload is in last segment */
         secdata = lustre_msg_buf(reqbuf, reqbuf->lm_bufcount - 1, 0);
         seclen = reqbuf->lm_buflens[reqbuf->lm_bufcount - 1];
@@ -2060,7 +2073,7 @@ int gss_svc_handle_init(struct ptlrpc_request *req,
                         CERROR("missing user descriptor\n");
                         RETURN(SECSVC_DROP);
                 }
-                if (sptlrpc_unpack_user_desc(reqbuf, 2)) {
+                if (sptlrpc_unpack_user_desc(reqbuf, 2, swabbed)) {
                         CERROR("Mal-formed user descriptor\n");
                         RETURN(SECSVC_DROP);
                 }
@@ -2087,6 +2100,7 @@ int gss_svc_verify_request(struct ptlrpc_request *req,
         struct gss_svc_ctx *gctx = grctx->src_ctx;
         struct lustre_msg  *msg = req->rq_reqbuf;
         int                 offset = 2;
+        int                 swabbed;
         ENTRY;
 
         *major = GSS_S_COMPLETE;
@@ -2119,6 +2133,8 @@ int gss_svc_verify_request(struct ptlrpc_request *req,
         }
 
 verified:
+        swabbed = ptlrpc_req_need_swab(req);
+
         /* user descriptor */
         if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
                 if (msg->lm_bufcount < (offset + 1)) {
@@ -2126,7 +2142,7 @@ verified:
                         RETURN(-EINVAL);
                 }
 
-                if (sptlrpc_unpack_user_desc(msg, offset)) {
+                if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
                         CERROR("Mal-formed user descriptor\n");
                         RETURN(-EINVAL);
                 }
@@ -2143,7 +2159,7 @@ verified:
                         RETURN(-EINVAL);
                 }
 
-                if (bulk_sec_desc_unpack(msg, offset))
+                if (bulk_sec_desc_unpack(msg, offset, swabbed))
                         RETURN(-EINVAL);
 
                 req->rq_pack_bulk = 1;
@@ -2164,7 +2180,7 @@ int gss_svc_unseal_request(struct ptlrpc_request *req,
 {
         struct gss_svc_ctx *gctx = grctx->src_ctx;
         struct lustre_msg  *msg = req->rq_reqbuf;
-        int                 msglen, offset = 1;
+        int                 swabbed, msglen, offset = 1;
         ENTRY;
 
         if (gss_check_seq_num(&gctx->gsc_seqdata, gw->gw_seq, 0)) {
@@ -2186,7 +2202,8 @@ int gss_svc_unseal_request(struct ptlrpc_request *req,
                 RETURN(-EACCES);
         }
 
-        if (lustre_unpack_msg(msg, msglen)) {
+        swabbed = __lustre_unpack_msg(msg, msglen);
+        if (swabbed < 0) {
                 CERROR("Failed to unpack after decryption\n");
                 RETURN(-EINVAL);
         }
@@ -2203,7 +2220,7 @@ int gss_svc_unseal_request(struct ptlrpc_request *req,
                         RETURN(-EINVAL);
                 }
 
-                if (sptlrpc_unpack_user_desc(msg, offset)) {
+                if (sptlrpc_unpack_user_desc(msg, offset, swabbed)) {
                         CERROR("Mal-formed user descriptor\n");
                         RETURN(-EINVAL);
                 }
@@ -2219,7 +2236,7 @@ int gss_svc_unseal_request(struct ptlrpc_request *req,
                         RETURN(-EINVAL);
                 }
 
-                if (bulk_sec_desc_unpack(msg, offset))
+                if (bulk_sec_desc_unpack(msg, offset, swabbed))
                         RETURN(-EINVAL);
 
                 req->rq_pack_bulk = 1;
@@ -2314,7 +2331,8 @@ int gss_svc_handle_destroy(struct ptlrpc_request *req,
                         CERROR("missing user descriptor, ignore it\n");
                         RETURN(SECSVC_OK);
                 }
-                if (sptlrpc_unpack_user_desc(req->rq_reqbuf, 2)) {
+                if (sptlrpc_unpack_user_desc(req->rq_reqbuf, 2,
+                                             ptlrpc_req_need_swab(req))) {
                         CERROR("Mal-formed user descriptor, ignore it\n");
                         RETURN(SECSVC_OK);
                 }
@@ -2331,7 +2349,7 @@ int gss_svc_accept(struct ptlrpc_sec_policy *policy, struct ptlrpc_request *req)
         struct gss_header      *ghdr;
         struct gss_svc_reqctx  *grctx;
         struct gss_wire_ctx    *gw;
-        int                     rc;
+        int                     swabbed, rc;
         ENTRY;
 
         LASSERT(req->rq_reqbuf);
@@ -2342,7 +2360,9 @@ int gss_svc_accept(struct ptlrpc_sec_policy *policy, struct ptlrpc_request *req)
                 RETURN(SECSVC_DROP);
         }
 
-        ghdr = gss_swab_header(req->rq_reqbuf, 0);
+        swabbed = ptlrpc_req_need_swab(req);
+
+        ghdr = gss_swab_header(req->rq_reqbuf, 0, swabbed);
         if (ghdr == NULL) {
                 CERROR("can't decode gss header\n");
                 RETURN(SECSVC_DROP);
@@ -2375,7 +2395,7 @@ int gss_svc_accept(struct ptlrpc_sec_policy *policy, struct ptlrpc_request *req)
         rawobj_from_netobj(&gw->gw_handle, &ghdr->gh_handle);
 
         /* keep original wire header which subject to checksum verification */
-        if (lustre_msg_swabbed(req->rq_reqbuf))
+        if (swabbed)
                 gss_header_swabber(ghdr);
 
         switch(ghdr->gh_proc) {
index 63475e2..d459393 100644 (file)
@@ -1399,7 +1399,8 @@ static int __req_capsule_offset(const struct req_capsule *pill,
                             pill->rc_fmt->rf_name,
                             field->rmf_name, offset, loc);
         offset --;
-        LASSERT(0 <= offset && offset < (sizeof(pill->rc_swabbed) << 3));
+
+        LASSERT(0 <= offset && offset < REQ_MAX_FIELD_NR);
         return offset;
 }
 
@@ -1413,6 +1414,7 @@ static void *__req_capsule_get(struct req_capsule *pill,
         void                    *value;
         int                      len;
         int                      offset;
+        int                      inout = loc == RCL_CLIENT;
 
         void *(*getter)(struct lustre_msg *m, int n, int minlen);
 
@@ -1443,11 +1445,10 @@ static void *__req_capsule_get(struct req_capsule *pill,
         value = getter(msg, offset, len);
 
         swabber = swabber ?: field->rmf_swabber;
-        if (!(pill->rc_swabbed & (1 << offset)) && loc != pill->rc_loc &&
-            swabber != NULL && value != NULL &&
-            lustre_msg_swabbed(msg)) {
+        if (ptlrpc_buf_need_swab(pill->rc_req, inout, offset) &&
+            swabber != NULL && value != NULL) {
                 swabber(value);
-                pill->rc_swabbed |= (1 << offset);
+                ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
         }
         if (value == NULL) {
                 DEBUG_REQ(D_ERROR, pill->rc_req,
@@ -1600,8 +1601,7 @@ void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt)
                 LASSERT(FMT_FIELD(fmt, i, j)->rmf_size >=
                         FMT_FIELD(old, i, j)->rmf_size);
         }
-        /* last field should be returned to the unswabbed state */
-        pill->rc_swabbed &= ~(__u32)(1 << j);
+
         pill->rc_fmt = fmt;
 }
 EXPORT_SYMBOL(req_capsule_extend);
index 407f755..ff46f97 100644 (file)
@@ -72,13 +72,28 @@ int lustre_msg_hdr_size(__u32 magic, int count)
 }
 EXPORT_SYMBOL(lustre_msg_hdr_size);
 
-int lustre_msg_swabbed(struct lustre_msg *msg)
+void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
+                            int index)
 {
-        return (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
+        if (inout)
+                lustre_set_req_swabbed(req, index);
+        else
+                lustre_set_rep_swabbed(req, index);
+}
+
+int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
+                         int index)
+{
+        if (inout)
+                return (ptlrpc_req_need_swab(req) &&
+                        !lustre_req_swabbed(req, index));
+        else
+                return (ptlrpc_rep_need_swab(req) &&
+                        !lustre_rep_swabbed(req, index));
 }
 
-static inline int
-lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
+static inline int lustre_msg_check_version_v2(struct lustre_msg_v2 *msg,
+                                              __u32 version)
 {
         __u32 ver = lustre_msg_get_version(msg);
         return (ver & LUSTRE_VERSION_MASK) != version;
@@ -88,11 +103,9 @@ int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
 {
         switch (msg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V1:
-        case LUSTRE_MSG_MAGIC_V1_SWABBED:
                 CERROR("msg v1 not supported - please upgrade you system\n");
                 return -EINVAL;
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return lustre_msg_check_version_v2(msg, version);
         default:
                 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
@@ -101,7 +114,8 @@ int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
 }
 
 /* early reply size */
-int lustre_msg_early_size() {
+int lustre_msg_early_size()
+{
         static int size = 0;
         if (!size)
                 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
@@ -201,7 +215,6 @@ static int lustre_pack_request_v2(struct ptlrpc_request *req,
 
         lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
         lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
-        lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
         return 0;
 }
 
@@ -329,7 +342,6 @@ int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
 
         lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
         lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
-        lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
 
         PTLRPC_RS_DEBUG_LRU_ADD(rs);
 
@@ -353,7 +365,6 @@ int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
 
         switch (req->rq_reqmsg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
                 break;
         default:
@@ -406,7 +417,6 @@ void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
 {
         switch (m->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return lustre_msg_buf_v2(m, n, min_size);
         default:
                 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
@@ -490,7 +500,7 @@ void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
 
 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
 {
-        int flipped, required_len, i;
+        int swabbed, required_len, i;
 
         /* Now we know the sender speaks my language. */
         required_len = lustre_msg_hdr_size_v2(0);
@@ -500,9 +510,10 @@ static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
                 return -EINVAL;
         }
 
-        flipped = lustre_msg_swabbed(m);
+        swabbed = (m->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
 
-        if (flipped) {
+        if (swabbed) {
+                __swab32s(&m->lm_magic);
                 __swab32s(&m->lm_bufcount);
                 __swab32s(&m->lm_secflvr);
                 __swab32s(&m->lm_repsize);
@@ -521,7 +532,7 @@ static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
         }
 
         for (i = 0; i < m->lm_bufcount; i++) {
-                if (flipped)
+                if (swabbed)
                         __swab32s(&m->lm_buflens[i]);
                 required_len += size_round(m->lm_buflens[i]);
         }
@@ -534,10 +545,10 @@ static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
                 return -EINVAL;
         }
 
-        return 0;
+        return swabbed;
 }
 
-int lustre_unpack_msg(struct lustre_msg *m, int len)
+int __lustre_unpack_msg(struct lustre_msg *m, int len)
 {
         int required_len, rc;
         ENTRY;
@@ -557,31 +568,49 @@ int lustre_unpack_msg(struct lustre_msg *m, int len)
                 RETURN(-EINVAL);
         }
 
-        switch (m->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
-                rc = lustre_unpack_msg_v2(m, len);
-                break;
-        default:
-                CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
-                return -EINVAL;
-        }
+        rc = lustre_unpack_msg_v2(m, len);
 
         RETURN(rc);
 }
+EXPORT_SYMBOL(__lustre_unpack_msg);
+
+int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len)
+{
+        int rc;
+        rc = __lustre_unpack_msg(req->rq_reqmsg, len);
+        if (rc == 1) {
+                lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+                rc = 0;
+        }
+        return rc;
+}
+
+int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len)
+{
+        int rc;
+        rc = __lustre_unpack_msg(req->rq_repmsg, len);
+        if (rc == 1) {
+                lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+                rc = 0;
+        }
+        return rc;
+}
 
-static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
-                                               int offset)
+static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
+                                               const int inout, int offset)
 {
         struct ptlrpc_body *pb;
+        struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
 
         pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
         if (!pb) {
                 CERROR("error unpacking ptlrpc body\n");
                 return -EFAULT;
         }
-        if (lustre_msg_swabbed(m))
+        if (ptlrpc_buf_need_swab(req, inout, offset)) {
                 lustre_swab_ptlrpc_body(pb);
+                ptlrpc_buf_set_swabbed(req, inout, offset);
+        }
 
         if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
                  CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
@@ -595,11 +624,9 @@ int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
 {
         switch (req->rq_reqmsg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
-                lustre_set_req_swabbed(req, offset);
-                return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
+                return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
         default:
-                CERROR("bad lustre msg magic: %#08X\n",
+                CERROR("bad lustre msg magic: %08x\n",
                        req->rq_reqmsg->lm_magic);
                 return -EINVAL;
         }
@@ -609,11 +636,9 @@ int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
 {
         switch (req->rq_repmsg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
-                lustre_set_rep_swabbed(req, offset);
-                return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
+                return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
         default:
-                CERROR("bad lustre msg magic: %#08X\n",
+                CERROR("bad lustre msg magic: %08x\n",
                        req->rq_repmsg->lm_magic);
                 return -EINVAL;
         }
@@ -638,7 +663,6 @@ int lustre_msg_buflen(struct lustre_msg *m, int n)
 {
         switch (m->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return lustre_msg_buflen_v2(m, n);
         default:
                 CERROR("incorrect message magic: %08x\n", m->lm_magic);
@@ -675,7 +699,6 @@ int lustre_msg_bufcount(struct lustre_msg *m)
 {
         switch (m->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return m->lm_bufcount;
         default:
                 CERROR("incorrect message magic: %08x\n", m->lm_magic);
@@ -692,7 +715,6 @@ char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
 
         switch (m->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 str = lustre_msg_buf_v2(m, index, 0);
                 blen = lustre_msg_buflen_v2(m, index);
                 break;
@@ -731,24 +753,21 @@ char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
 }
 
 /* Wrap up the normal fixed length cases */
-void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
-                      void *swabber)
+static inline void *__lustre_swab_buf(struct lustre_msg *msg, int index,
+                                      int min_size, void *swabber)
 {
         void *ptr = NULL;
 
         LASSERT(msg != NULL);
         switch (msg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 ptr = lustre_msg_buf_v2(msg, index, min_size);
                 break;
         default:
                 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
         }
-        if (ptr == NULL)
-                return NULL;
 
-        if (swabber != NULL && lustre_msg_swabbed(msg))
+        if (ptr && swabber)
                 ((void (*)(void *))swabber)(ptr);
 
         return ptr;
@@ -757,21 +776,21 @@ void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
                          void *swabber)
 {
-        if (lustre_req_swabbed(req, index))
+        if (!ptlrpc_buf_need_swab(req, 1, index))
                 return lustre_msg_buf(req->rq_reqmsg, index, min_size);
 
         lustre_set_req_swabbed(req, index);
-        return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
+        return __lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
 }
 
-void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
-                         void *swabber)
+void *lustre_swab_repbuf(struct ptlrpc_request *req, int index,
+                         int min_size, void *swabber)
 {
-        if (lustre_rep_swabbed(req, index))
+        if (!ptlrpc_buf_need_swab(req, 0, index))
                 return lustre_msg_buf(req->rq_repmsg, index, min_size);
 
         lustre_set_rep_swabbed(req, index);
-        return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
+        return __lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
 }
 
 static inline struct ptlrpc_body *lustre_msg_ptlrpc_body(struct lustre_msg *msg)
@@ -787,7 +806,6 @@ __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
         case LUSTRE_MSG_MAGIC_V1_SWABBED:
                 return 0;
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 /* already in host endian */
                 return msg->lm_flags;
         default:
@@ -813,8 +831,7 @@ void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -860,8 +877,7 @@ void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
@@ -875,8 +891,7 @@ void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -920,8 +935,7 @@ void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -938,8 +952,7 @@ struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
 __u32 lustre_msg_get_type(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -956,8 +969,7 @@ __u32 lustre_msg_get_type(struct lustre_msg *msg)
 __u32 lustre_msg_get_version(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -974,8 +986,7 @@ __u32 lustre_msg_get_version(struct lustre_msg *msg)
 void lustre_msg_add_version(struct lustre_msg *msg, int version)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                 pb->pb_version |= version;
@@ -989,8 +1000,7 @@ void lustre_msg_add_version(struct lustre_msg *msg, int version)
 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1000,6 +1010,7 @@ __u32 lustre_msg_get_opc(struct lustre_msg *msg)
         }
         default:
                 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
+                LBUG();
                 return 0;
         }
 }
@@ -1007,8 +1018,7 @@ __u32 lustre_msg_get_opc(struct lustre_msg *msg)
 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1025,8 +1035,7 @@ __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1062,8 +1071,7 @@ __u64 *lustre_msg_get_versions(struct lustre_msg *msg)
 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1080,8 +1088,7 @@ __u64 lustre_msg_get_transno(struct lustre_msg *msg)
 int lustre_msg_get_status(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1099,8 +1106,7 @@ int lustre_msg_get_status(struct lustre_msg *msg)
 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1109,7 +1115,7 @@ __u64 lustre_msg_get_slv(struct lustre_msg *msg)
                 return pb->pb_slv;
         }
         default:
-                CERROR("invalid msg magic %x\n", msg->lm_magic);
+                CERROR("invalid msg magic %08x\n", msg->lm_magic);
                 return -EINVAL;
         }
 }
@@ -1118,8 +1124,7 @@ __u64 lustre_msg_get_slv(struct lustre_msg *msg)
 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1137,8 +1142,7 @@ void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1156,8 +1160,7 @@ __u32 lustre_msg_get_limit(struct lustre_msg *msg)
 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1167,7 +1170,7 @@ void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
                 return;
         }
         default:
-                CERROR("invalid msg magic %x\n", msg->lm_magic);
+                CERROR("invalid msg magic %08x\n", msg->lm_magic);
                 return;
         }
 }
@@ -1175,8 +1178,7 @@ void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1205,7 +1207,6 @@ __u32 lustre_msg_get_magic(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return msg->lm_magic;
         default:
                 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
@@ -1219,8 +1220,7 @@ __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
         case LUSTRE_MSG_MAGIC_V1:
         case LUSTRE_MSG_MAGIC_V1_SWABBED:
                 return 0;
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1241,8 +1241,7 @@ __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
         case LUSTRE_MSG_MAGIC_V1:
         case LUSTRE_MSG_MAGIC_V1_SWABBED:
                 return 0;
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 if (!pb) {
                         CERROR("invalid msg %p: no ptlrpc body!\n", msg);
@@ -1260,11 +1259,7 @@ __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V1:
-        case LUSTRE_MSG_MAGIC_V1_SWABBED:
-                return 0;
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return msg->lm_cksum;
         default:
                 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
@@ -1275,11 +1270,7 @@ __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
 {
         switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V1:
-        case LUSTRE_MSG_MAGIC_V1_SWABBED:
-                return 0;
-        case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED: {
+        case LUSTRE_MSG_MAGIC_V2: {
                 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                 return crc32_le(~(__u32)0, (unsigned char *)pb, sizeof(*pb));
@@ -2205,7 +2196,6 @@ static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
 
         switch (req->rq_reqmsg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
         default:
                 CERROR("bad lustre msg magic: %#08X\n",
@@ -2220,7 +2210,6 @@ static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
 
         switch (req->rq_repmsg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V2:
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
         default:
                 /* uninitialized yet */
@@ -2232,7 +2221,6 @@ 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,
index 05bcdfc..50fec42 100644 (file)
@@ -223,7 +223,6 @@ EXPORT_SYMBOL(ptlrpc_service_health_check);
 EXPORT_SYMBOL(ptlrpc_hpreq_reorder);
 
 /* pack_generic.c */
-EXPORT_SYMBOL(lustre_msg_swabbed);
 EXPORT_SYMBOL(lustre_msg_check_version);
 EXPORT_SYMBOL(lustre_pack_request);
 EXPORT_SYMBOL(lustre_pack_reply);
@@ -232,11 +231,13 @@ EXPORT_SYMBOL(lustre_shrink_msg);
 EXPORT_SYMBOL(lustre_free_reply_state);
 EXPORT_SYMBOL(lustre_msg_size);
 EXPORT_SYMBOL(lustre_packed_msg_size);
-EXPORT_SYMBOL(lustre_unpack_msg);
+EXPORT_SYMBOL(ptlrpc_unpack_rep_msg);
+EXPORT_SYMBOL(ptlrpc_unpack_req_msg);
 EXPORT_SYMBOL(lustre_msg_buf);
 EXPORT_SYMBOL(lustre_msg_string);
+EXPORT_SYMBOL(ptlrpc_buf_set_swabbed);
+EXPORT_SYMBOL(ptlrpc_buf_need_swab);
 EXPORT_SYMBOL(lustre_swab_ptlrpc_body);
-EXPORT_SYMBOL(lustre_swab_buf);
 EXPORT_SYMBOL(lustre_swab_reqbuf);
 EXPORT_SYMBOL(lustre_swab_repbuf);
 EXPORT_SYMBOL(lustre_swab_obdo);
index 278bc7e..6926fc9 100644 (file)
@@ -947,7 +947,6 @@ static int do_cli_unwrap_reply(struct ptlrpc_request *req)
 {
         struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
         int                    rc;
-        __u32                  flvr;
         ENTRY;
 
         LASSERT(ctx);
@@ -956,32 +955,33 @@ static int do_cli_unwrap_reply(struct ptlrpc_request *req)
         LASSERT(req->rq_repdata);
         LASSERT(req->rq_repmsg == NULL);
 
+        req->rq_rep_swab_mask = 0;
+
+        rc = __lustre_unpack_msg(req->rq_repdata, req->rq_repdata_len);
+        switch (rc) {
+        case 1:
+                lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+        case 0:
+                break;
+        default:
+                CERROR("failed unpack reply: x"LPU64"\n", req->rq_xid);
+                RETURN(-EPROTO);
+        }
+
         if (req->rq_repdata_len < sizeof(struct lustre_msg)) {
                 CERROR("replied data length %d too small\n",
                        req->rq_repdata_len);
                 RETURN(-EPROTO);
         }
 
-        /* v2 message, check request/reply policy match */
-        flvr = WIRE_FLVR(req->rq_repdata->lm_secflvr);
-
-        if (req->rq_repdata->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED)
-                __swab32s(&flvr);
-
-        if (SPTLRPC_FLVR_POLICY(flvr) !=
+        if (SPTLRPC_FLVR_POLICY(req->rq_repdata->lm_secflvr) !=
             SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc)) {
-                CERROR("request policy was %u while reply with %u\n",
-                       SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc),
-                       SPTLRPC_FLVR_POLICY(flvr));
+                CERROR("reply policy %u doesn't match request policy %u\n",
+                       SPTLRPC_FLVR_POLICY(req->rq_repdata->lm_secflvr),
+                       SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc));
                 RETURN(-EPROTO);
         }
 
-        /* do nothing if it's null policy; otherwise unpack the
-         * wrapper message */
-        if (SPTLRPC_FLVR_POLICY(flvr) != SPTLRPC_POLICY_NULL &&
-            lustre_unpack_msg(req->rq_repdata, req->rq_repdata_len))
-                RETURN(-EPROTO);
-
         switch (SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc)) {
         case SPTLRPC_SVC_NULL:
         case SPTLRPC_SVC_AUTH:
@@ -996,8 +996,11 @@ static int do_cli_unwrap_reply(struct ptlrpc_request *req)
         default:
                 LBUG();
         }
-
         LASSERT(rc || req->rq_repmsg || req->rq_resend);
+
+        if (SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) != SPTLRPC_POLICY_NULL &&
+            !req->rq_ctx_init)
+                req->rq_rep_swab_mask = 0;
         RETURN(rc);
 }
 
@@ -1095,6 +1098,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
         memcpy(early_buf, req->rq_repbuf, early_size);
         spin_unlock(&req->rq_lock);
 
+        spin_lock_init(&early_req->rq_lock);
         early_req->rq_cli_ctx = sptlrpc_cli_ctx_get(req->rq_cli_ctx);
         early_req->rq_flvr = req->rq_flvr;
         early_req->rq_repbuf = early_buf;
@@ -1950,36 +1954,24 @@ int sptlrpc_svc_unwrap_request(struct ptlrpc_request *req)
         LASSERT(req->rq_repmsg == NULL);
         LASSERT(req->rq_svc_ctx == NULL);
 
-        req->rq_sp_from = LUSTRE_SP_ANY;
-        req->rq_auth_uid = INVALID_UID;
-        req->rq_auth_mapped_uid = INVALID_UID;
-
-        if (req->rq_reqdata_len < sizeof(struct lustre_msg)) {
-                CERROR("request size %d too small\n", req->rq_reqdata_len);
-                RETURN(SECSVC_DROP);
-        }
+        req->rq_req_swab_mask = 0;
 
-        /*
-         * only expect v2 message.
-         */
-        switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                req->rq_flvr.sf_rpc = WIRE_FLVR(msg->lm_secflvr);
-                break;
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
-                req->rq_flvr.sf_rpc = WIRE_FLVR(__swab32(msg->lm_secflvr));
+        rc = __lustre_unpack_msg(msg, req->rq_reqdata_len);
+        switch (rc) {
+        case 1:
+                lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+        case 0:
                 break;
         default:
-                CERROR("invalid magic %x\n", msg->lm_magic);
+                CERROR("error unpacking request from %s x"LPU64"\n",
+                       libcfs_id2str(req->rq_peer), req->rq_xid);
                 RETURN(SECSVC_DROP);
         }
 
-        /* unpack the wrapper message if the policy is not null */
-        if (SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) != SPTLRPC_POLICY_NULL &&
-            lustre_unpack_msg(msg, req->rq_reqdata_len)) {
-                CERROR("invalid wrapper msg format\n");
-                RETURN(SECSVC_DROP);
-        }
+        req->rq_flvr.sf_rpc = WIRE_FLVR(msg->lm_secflvr);
+        req->rq_sp_from = LUSTRE_SP_ANY;
+        req->rq_auth_uid = INVALID_UID;
+        req->rq_auth_mapped_uid = INVALID_UID;
 
         policy = sptlrpc_wireflavor2policy(req->rq_flvr.sf_rpc);
         if (!policy) {
@@ -1989,10 +1981,16 @@ int sptlrpc_svc_unwrap_request(struct ptlrpc_request *req)
 
         LASSERT(policy->sp_sops->accept);
         rc = policy->sp_sops->accept(req);
-
+        sptlrpc_policy_put(policy);
         LASSERT(req->rq_reqmsg || rc != SECSVC_OK);
         LASSERT(req->rq_svc_ctx || rc == SECSVC_DROP);
-        sptlrpc_policy_put(policy);
+
+        /*
+         * if it's not null flavor (which means embedded packing msg),
+         * reset the swab mask for the comming inner msg unpacking.
+         */
+        if (SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) != SPTLRPC_POLICY_NULL)
+                req->rq_req_swab_mask = 0;
 
         /* sanity check for the request source */
         rc = sptlrpc_svc_check_from(req, rc);
@@ -2310,7 +2308,7 @@ int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset)
 }
 EXPORT_SYMBOL(sptlrpc_pack_user_desc);
 
-int sptlrpc_unpack_user_desc(struct lustre_msg *msg, int offset)
+int sptlrpc_unpack_user_desc(struct lustre_msg *msg, int offset, int swabbed)
 {
         struct ptlrpc_user_desc *pud;
         int                      i;
@@ -2319,7 +2317,7 @@ int sptlrpc_unpack_user_desc(struct lustre_msg *msg, int offset)
         if (!pud)
                 return -EINVAL;
 
-        if (lustre_msg_swabbed(msg)) {
+        if (swabbed) {
                 __swab32s(&pud->pud_uid);
                 __swab32s(&pud->pud_gid);
                 __swab32s(&pud->pud_fsuid);
@@ -2340,7 +2338,7 @@ int sptlrpc_unpack_user_desc(struct lustre_msg *msg, int offset)
                 return -EINVAL;
         }
 
-        if (lustre_msg_swabbed(msg)) {
+        if (swabbed) {
                 for (i = 0; i < pud->pud_ngroups; i++)
                         __swab32s(&pud->pud_groups[i]);
         }
index 0dc38e4..05c8116 100644 (file)
@@ -855,7 +855,7 @@ __u8 sptlrpc_get_hash_alg(const char *algname)
 }
 EXPORT_SYMBOL(sptlrpc_get_hash_alg);
 
-int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset)
+int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset, int swabbed)
 {
         struct ptlrpc_bulk_sec_desc *bsd;
         int                          size = msg->lm_buflens[offset];
@@ -866,7 +866,7 @@ int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset)
                 return -EINVAL;
         }
 
-        if (lustre_msg_swabbed(msg)) {
+        if (swabbed) {
                 __swab32s(&bsd->bsd_nob);
         }
 
index 08baf12..041217e 100644 (file)
@@ -71,14 +71,7 @@ void null_encode_sec_part(struct lustre_msg *msg, enum lustre_sec_part sp)
 static inline
 enum lustre_sec_part null_decode_sec_part(struct lustre_msg *msg)
 {
-        switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return (msg->lm_secflvr >> 24) & 0xFF;
-        case LUSTRE_MSG_MAGIC_V2_SWABBED:
-                return (msg->lm_secflvr) & 0xFF;
-        default:
-                return LUSTRE_SP_ANY;
-        }
+        return (msg->lm_secflvr >> 24) & 0xFF;
 }
 
 static int null_ctx_refresh(struct ptlrpc_cli_ctx *ctx)
@@ -109,15 +102,12 @@ int null_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req)
 
         LASSERT(req->rq_repdata);
 
-        if (req->rq_early) {
-                cksums = req->rq_repdata->lm_cksum;
-                req->rq_repdata->lm_cksum = 0;
-
-                if (req->rq_repdata->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED)
-                        __swab32s(&cksums);
+        req->rq_repmsg = req->rq_repdata;
+        req->rq_replen = req->rq_repdata_len;
 
-                cksumc = crc32_le(!(__u32) 0, (unsigned char *)req->rq_repdata,
-                                  req->rq_repdata_len);
+        if (req->rq_early) {
+                cksums = lustre_msg_get_cksum(req->rq_repdata);
+                cksumc = lustre_msg_calc_cksum(req->rq_repmsg);
                 if (cksumc != cksums) {
                         CWARN("early reply checksum mismatch: %08x != %08x\n",
                               cksumc, cksums);
@@ -125,8 +115,6 @@ int null_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req)
                 }
         }
 
-        req->rq_repmsg = req->rq_repdata;
-        req->rq_replen = req->rq_repdata_len;
         return 0;
 }
 
@@ -370,10 +358,8 @@ int null_authorize(struct ptlrpc_request *req)
                 else
                         req->rq_reply_off = 0;
         } else {
-                rs->rs_repbuf->lm_cksum =
-                                crc32_le(!(__u32) 0,
-                                         (unsigned char *)rs->rs_repbuf,
-                                         rs->rs_repdata_len);
+                lustre_msg_set_cksum(rs->rs_repbuf,
+                                     lustre_msg_calc_cksum(rs->rs_repbuf));
                 req->rq_reply_off = 0;
         }
 
index 9b03d77..2b34adc 100644 (file)
@@ -102,11 +102,11 @@ struct plain_bulk_token {
  * bulk checksum helpers                *
  ****************************************/
 
-static int plain_unpack_bsd(struct lustre_msg *msg)
+static int plain_unpack_bsd(struct lustre_msg *msg, int swabbed)
 {
         struct ptlrpc_bulk_sec_desc *bsd;
 
-        if (bulk_sec_desc_unpack(msg, PLAIN_PACK_BULK_OFF))
+        if (bulk_sec_desc_unpack(msg, PLAIN_PACK_BULK_OFF, swabbed))
                 return -EPROTO;
 
         bsd = lustre_msg_buf(msg, PLAIN_PACK_BULK_OFF, PLAIN_BSD_SIZE);
@@ -239,6 +239,7 @@ int plain_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req)
         struct lustre_msg   *msg = req->rq_repdata;
         struct plain_header *phdr;
         __u32                cksum;
+        int                  swabbed;
         ENTRY;
 
         if (msg->lm_bufcount != PLAIN_PACK_SEGMENTS) {
@@ -246,6 +247,8 @@ int plain_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req)
                 RETURN(-EPROTO);
         }
 
+        swabbed = ptlrpc_rep_need_swab(req);
+
         phdr = lustre_msg_buf(msg, PLAIN_PACK_HDR_OFF, sizeof(*phdr));
         if (phdr == NULL) {
                 CERROR("missing plain header\n");
@@ -290,7 +293,7 @@ int plain_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req)
                 }
 
                 if (phdr->ph_flags & PLAIN_FL_BULK) {
-                        if (plain_unpack_bsd(msg))
+                        if (plain_unpack_bsd(msg, swabbed))
                                 RETURN(-EPROTO);
                 }
         }
@@ -738,6 +741,7 @@ int plain_accept(struct ptlrpc_request *req)
 {
         struct lustre_msg   *msg = req->rq_reqbuf;
         struct plain_header *phdr;
+        int                  swabbed;
         ENTRY;
 
         LASSERT(SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) ==
@@ -756,6 +760,8 @@ int plain_accept(struct ptlrpc_request *req)
                 RETURN(SECSVC_DROP);
         }
 
+        swabbed = ptlrpc_req_need_swab(req);
+
         phdr = lustre_msg_buf(msg, PLAIN_PACK_HDR_OFF, sizeof(*phdr));
         if (phdr == NULL) {
                 CERROR("missing plain header\n");
@@ -776,7 +782,8 @@ int plain_accept(struct ptlrpc_request *req)
         req->rq_flvr.u_bulk.hash.hash_alg = phdr->ph_bulk_hash_alg;
 
         if (phdr->ph_flags & PLAIN_FL_USER) {
-                if (sptlrpc_unpack_user_desc(msg, PLAIN_PACK_USER_OFF)) {
+                if (sptlrpc_unpack_user_desc(msg, PLAIN_PACK_USER_OFF,
+                                             swabbed)) {
                         CERROR("Mal-formed user descriptor\n");
                         RETURN(SECSVC_DROP);
                 }
@@ -786,7 +793,7 @@ int plain_accept(struct ptlrpc_request *req)
         }
 
         if (phdr->ph_flags & PLAIN_FL_BULK) {
-                if (plain_unpack_bsd(msg))
+                if (plain_unpack_bsd(msg, swabbed))
                         RETURN(SECSVC_DROP);
 
                 req->rq_pack_bulk = 1;
index 76bcc24..060d741 100644 (file)
@@ -1337,15 +1337,18 @@ ptlrpc_server_handle_req_in(struct ptlrpc_service *svc)
                 LBUG();
         }
 
-        /* Clear request swab mask; this is a new request */
-        req->rq_req_swab_mask = 0;
-
-        rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
-        if (rc != 0) {
-                CERROR("error unpacking request: ptl %d from %s x"LPU64"\n",
-                       svc->srv_req_portal, libcfs_id2str(req->rq_peer),
-                       req->rq_xid);
-                goto err_req;
+        /*
+         * for null-flavored rpc, msg has been unpacked by sptlrpc, although
+         * redo it wouldn't be harmful.
+         */
+        if (SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) != SPTLRPC_POLICY_NULL) {
+                rc = ptlrpc_unpack_req_msg(req, req->rq_reqlen);
+                if (rc != 0) {
+                        CERROR("error unpacking request: ptl %d from %s "
+                               "x"LPU64"\n", svc->srv_req_portal,
+                               libcfs_id2str(req->rq_peer), req->rq_xid);
+                        goto err_req;
+                }
         }
 
         rc = lustre_unpack_req_ptlrpc_body(req, MSG_PTLRPC_BODY_OFF);