pill->rc_fmt->rf_name,
field->rmf_name, offset, loc);
offset --;
- LASSERT(0 <= offset && offset < REQ_MAX_FIELD_NR);
+ LASSERT(0 <= offset && offset < (sizeof(pill->rc_swabbed) << 3));
return offset;
}
void *value;
int len;
int offset;
- int inout = loc == RCL_CLIENT;
void *(*getter)(struct lustre_msg *m, int n, int minlen);
value = getter(msg, offset, len);
swabber = swabber ?: field->rmf_swabber;
- if (ptlrpc_req_need_swab(pill->rc_req, inout, offset) &&
- swabber != NULL && value != NULL) {
+ if (!(pill->rc_swabbed & (1 << offset)) && loc != pill->rc_loc &&
+ swabber != NULL && value != NULL &&
+ lustre_msg_swabbed(msg)) {
swabber(value);
- ptlrpc_req_set_swabbed(pill->rc_req, inout, offset);
+ pill->rc_swabbed |= (1 << offset);
}
-
if (value == NULL) {
DEBUG_REQ(D_ERROR, pill->rc_req,
"Wrong buffer for field `%s' (%d of %d) "
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);
}
EXPORT_SYMBOL(lustre_msg_hdr_size);
-int lustre_msg_need_swab(struct lustre_msg *msg)
+int lustre_msg_swabbed(struct lustre_msg *msg)
{
return (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
}
-/**
- * \ret 0 - if need swabbed
- * \ret 1 - otherwise
- */
-static int ptlrpc_reqbuf_need_swab(struct ptlrpc_request *req, int index)
-{
- return (lustre_req_need_swab(req) && !lustre_req_swabbed(req, index));
-}
-
-/**
- * \ret 0 - if need swabbed
- * \ret 1 - otherwise
- */
-static int ptlrpc_repbuf_need_swab(struct ptlrpc_request *req, int index)
-{
- return (lustre_rep_need_swab(req) && !lustre_rep_swabbed(req, index));
-}
-
-/**
- * ptlrpc_req_need_swab - check the @req if need swab.
- * @req - ptlrpc_request need to look at.
- * @inout - =1 reqbuf, =0 repbuf.
- * @index - message offset
- *
- * \ret 0 - swabbed
- * \ret 1 - need swab
- */
-int ptlrpc_req_need_swab(struct ptlrpc_request *req, int inout, int index)
-{
- if (inout)
- return ptlrpc_reqbuf_need_swab(req, index);
- else
- return ptlrpc_repbuf_need_swab(req, index);
-}
-
-void ptlrpc_req_set_swabbed(struct ptlrpc_request *req, int inout, int index)
-{
- if(inout)
- lustre_set_req_swabbed(req, index);
- else
- lustre_set_rep_swabbed(req, index);
-}
-
-
static inline int
lustre_msg_check_version_v2(struct lustre_msg_v2 *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);
return -EINVAL;
}
- flipped = lustre_msg_need_swab(m);
+ flipped = lustre_msg_swabbed(m);
+
if (flipped) {
- __swab32s(&m->lm_magic);
__swab32s(&m->lm_bufcount);
__swab32s(&m->lm_secflvr);
__swab32s(&m->lm_repsize);
len, m->lm_bufcount);
return -EINVAL;
}
-
+
for (i = 0; i < m->lm_bufcount; i++) {
if (flipped)
__swab32s(&m->lm_buflens[i]);
return -EINVAL;
}
- return flipped;
+ return 0;
}
int lustre_unpack_msg(struct lustre_msg *m, int len)
RETURN(rc);
}
-static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
- int inout,
+static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
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 (ptlrpc_req_need_swab(req, inout, offset)) {
+ if (lustre_msg_swabbed(m))
lustre_swab_ptlrpc_body(pb);
- ptlrpc_req_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);
return -EINVAL;
}
- return 0;
+ return flipped;
}
int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
{
switch (req->rq_reqmsg->lm_magic) {
case LUSTRE_MSG_MAGIC_V2:
- return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
+ case LUSTRE_MSG_MAGIC_V2_SWABBED:
+ lustre_set_req_swabbed(req, offset);
+ return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
default:
CERROR("bad lustre msg magic: %#08X\n",
req->rq_reqmsg->lm_magic);
{
switch (req->rq_repmsg->lm_magic) {
case LUSTRE_MSG_MAGIC_V2:
- return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
+ case LUSTRE_MSG_MAGIC_V2_SWABBED:
+ lustre_set_rep_swabbed(req, offset);
+ return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
default:
CERROR("bad lustre msg magic: %#08X\n",
req->rq_repmsg->lm_magic);
if (ptr == NULL)
return NULL;
- if (swabber != NULL)
+ if (swabber != NULL && lustre_msg_swabbed(msg))
((void (*)(void *))swabber)(ptr);
return ptr;
void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
void *swabber)
{
- if (!ptlrpc_reqbuf_need_swab(req, index))
- swabber = NULL;
-
lustre_set_req_swabbed(req, index);
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)
{
- if (!ptlrpc_repbuf_need_swab(req, index))
- swabber = NULL;
-
lustre_set_rep_swabbed(req, index);
return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
}