#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
return req->rq_rep_swab_mask & (1 << index);
}
+static inline int lustre_req_need_swab(struct ptlrpc_request *req)
+{
+ return req->rq_req_swab_mask & (1 << MSG_PTLRPC_HEADER_OFF);
+}
+
+static inline int lustre_rep_need_swab(struct ptlrpc_request *req)
+{
+ return req->rq_rep_swab_mask & (1 << MSG_PTLRPC_HEADER_OFF);
+}
+
static inline const char *
ptlrpc_rqphase2str(const struct ptlrpc_request *req)
{
/* ptlrpc/pack_generic.c */
int ptlrpc_reconnect_import(struct obd_import *imp);
-int lustre_msg_swabbed(struct lustre_msg *msg);
+int ptlrpc_req_need_swab(struct ptlrpc_request *req, int inout, int index);
+void ptlrpc_req_set_swabbed(struct ptlrpc_request *req, int inout, int index);
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);
case LOV_MAGIC_V3:
return &lsm_v3_ops;
default:
- CERROR("Cannot recognize lsm_magic %d\n", magic);
+ CERROR("Cannot recognize lsm_magic %x\n", magic);
return NULL;
}
}
CDEBUG(D_INFO, "Missing/short RC vector on BRW_WRITE reply\n");
return(-EPROTO);
}
- if (lustre_msg_swabbed(req->rq_repmsg))
+ if (lustre_rep_need_swab(req))
for (i = 0; i < niocount; i++)
__swab32s(&remote_rcs[i]);
CERROR("Missing/short niobuf\n");
GOTO(out, rc = -EFAULT);
}
- if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
+
+ if (lustre_req_need_swab(req)) { /* swab remaining niobufs */
for (i = 1; i < niocount; i++)
lustre_swab_niobuf_remote (&remote_nb[i]);
}
if (exp->exp_failed)
GOTO(out, rc = -ENOTCONN);
- swab = lustre_msg_swabbed(req->rq_reqmsg);
+ swab = lustre_req_need_swab(req);
body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
lustre_swab_ost_body);
if (body == NULL) {
req->rq_rep_swab_mask = 0;
rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
- if (rc) {
+ if (rc < 0) {
DEBUG_REQ(D_ERROR, req, "unpack_rep failed: %d", rc);
return(-EPROTO);
}
+ if (rc > 0)
+ lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+
rc = lustre_unpack_rep_ptlrpc_body(req, MSG_PTLRPC_BODY_OFF);
if (rc) {
DEBUG_REQ(D_ERROR, req, "unpack ptlrpc body failed: %d", rc);
return(-EPROTO);
}
+
return 0;
}
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;
}
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 (!(pill->rc_swabbed & (1 << offset)) && loc != pill->rc_loc &&
- swabber != NULL && value != NULL &&
- lustre_msg_swabbed(msg)) {
+ if (ptlrpc_req_need_swab(pill->rc_req, inout, offset) &&
+ swabber != NULL && value != NULL) {
swabber(value);
- pill->rc_swabbed |= (1 << offset);
+ ptlrpc_req_set_swabbed(pill->rc_req, inout, 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_swabbed(struct lustre_msg *msg)
+int lustre_msg_need_swab(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_swabbed(m);
-
+ flipped = lustre_msg_need_swab(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 0;
+ return flipped;
}
int lustre_unpack_msg(struct lustre_msg *m, int len)
RETURN(rc);
}
-static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
+static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
+ 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_req_need_swab(req, inout, offset)) {
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);
{
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",
req->rq_reqmsg->lm_magic);
{
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",
req->rq_repmsg->lm_magic);
if (ptr == NULL)
return NULL;
- if (swabber != NULL && lustre_msg_swabbed(msg))
+ if (swabber != NULL)
((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);
}
void ptl_rpc_wipe_bulk_pages(struct ptlrpc_bulk_desc *desc);
/* pack_generic.c */
+int lustre_msg_need_swab(struct lustre_msg *msg);
struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc);
void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs);
EXPORT_SYMBOL(ptlrpc_service_health_check);
/* pack_generic.c */
-EXPORT_SYMBOL(lustre_msg_swabbed);
EXPORT_SYMBOL(lustre_msg_check_version);
EXPORT_SYMBOL(lustre_pack_request);
EXPORT_SYMBOL(lustre_pack_reply);
if (!pud)
return -EINVAL;
- if (lustre_msg_swabbed(msg)) {
+ if (lustre_msg_need_swab(msg)) {
__swab32s(&pud->pud_uid);
__swab32s(&pud->pud_gid);
__swab32s(&pud->pud_fsuid);
return -EINVAL;
}
- if (lustre_msg_swabbed(msg)) {
+ if (lustre_msg_need_swab(msg)) {
for (i = 0; i < pud->pud_ngroups; i++)
__swab32s(&pud->pud_groups[i]);
}
req->rq_req_swab_mask = 0;
rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
- if (rc != 0) {
+ 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;
}
+ if (rc > 0)
+ lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+
rc = lustre_unpack_req_ptlrpc_body(req, MSG_PTLRPC_BODY_OFF);
if (rc) {
CERROR ("error unpacking ptlrpc body: ptl %d from %s x"