#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
}
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;
}
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);
};
}
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;
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 *
/* 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);
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,
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];
};
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)
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)
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;
}
}
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);
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);
}
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);
}
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)) {
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));
*
* 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;
}
/* 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;
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]);
}
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)
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);
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);
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)
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);
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)
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);
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);
}
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);
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]);
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);
RETURN(-EFAULT);
}
+ swab = ptlrpc_req_need_swab(req);
if (swab) {
/* swab remaining niobufs */
for (i = 1; i < niocount; i++)
{
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);
}
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;
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;
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;
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);
__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;
}
return ghdr;
}
+#if 0
static
void gss_netobj_swabber(netobj_t *obj)
{
return obj;
}
+#endif
/*
* payload should be obtained from mechanism. but currently since we
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);
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);
RETURN(-EPROTO);
}
- if (lustre_msg_swabbed(msg))
+ if (swabbed)
gss_header_swabber(ghdr);
major = gss_verify_msg(msg, gctx->gc_mechctx, reqhdr->gh_svc);
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);
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;
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);
RETURN(-EPROTO);
}
- if (lustre_msg_swabbed(msg))
+ if (swabbed)
gss_header_swabber(ghdr);
/* use rq_repdata_len as buffer size, which assume unseal
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);
}
}
/* 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);
}
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,
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];
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);
}
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;
}
verified:
+ swabbed = ptlrpc_req_need_swab(req);
+
/* user descriptor */
if (gw->gw_flags & LUSTRE_GSS_PACK_USER) {
if (msg->lm_bufcount < (offset + 1)) {
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);
}
RETURN(-EINVAL);
}
- if (bulk_sec_desc_unpack(msg, offset))
+ if (bulk_sec_desc_unpack(msg, offset, swabbed))
RETURN(-EINVAL);
req->rq_pack_bulk = 1;
{
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)) {
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);
}
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);
}
RETURN(-EINVAL);
}
- if (bulk_sec_desc_unpack(msg, offset))
+ if (bulk_sec_desc_unpack(msg, offset, swabbed))
RETURN(-EINVAL);
req->rq_pack_bulk = 1;
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);
}
struct gss_header *ghdr;
struct gss_svc_reqctx *grctx;
struct gss_wire_ctx *gw;
- int rc;
+ int swabbed, rc;
ENTRY;
LASSERT(req->rq_reqbuf);
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);
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) {
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_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,
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);
}
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;
{
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);
}
/* 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);
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;
}
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);
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:
{
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);
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);
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);
}
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]);
}
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;
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);
{
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;
}
{
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;
}
{
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);
{
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);
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;
}
/* 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;
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)
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:
__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);
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);
__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);
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);
__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);
__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);
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;
__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);
}
default:
CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
+ LBUG();
return 0;
}
}
__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);
__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);
__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);
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);
__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);
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;
}
}
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);
__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);
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);
return;
}
default:
- CERROR("invalid msg magic %x\n", msg->lm_magic);
+ CERROR("invalid msg magic %08x\n", msg->lm_magic);
return;
}
}
__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);
{
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);
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);
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);
__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);
__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));
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",
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 */
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,
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);
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);
{
struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
int rc;
- __u32 flvr;
ENTRY;
LASSERT(ctx);
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:
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);
}
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;
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) {
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);
}
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;
if (!pud)
return -EINVAL;
- if (lustre_msg_swabbed(msg)) {
+ if (swabbed) {
__swab32s(&pud->pud_uid);
__swab32s(&pud->pud_gid);
__swab32s(&pud->pud_fsuid);
return -EINVAL;
}
- if (lustre_msg_swabbed(msg)) {
+ if (swabbed) {
for (i = 0; i < pud->pud_ngroups; i++)
__swab32s(&pud->pud_groups[i]);
}
}
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];
return -EINVAL;
}
- if (lustre_msg_swabbed(msg)) {
+ if (swabbed) {
__swab32s(&bsd->bsd_nob);
}
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)
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);
}
}
- req->rq_repmsg = req->rq_repdata;
- req->rq_replen = req->rq_repdata_len;
return 0;
}
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;
}
* 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);
struct lustre_msg *msg = req->rq_repdata;
struct plain_header *phdr;
__u32 cksum;
+ int swabbed;
ENTRY;
if (msg->lm_bufcount != PLAIN_PACK_SEGMENTS) {
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");
}
if (phdr->ph_flags & PLAIN_FL_BULK) {
- if (plain_unpack_bsd(msg))
+ if (plain_unpack_bsd(msg, swabbed))
RETURN(-EPROTO);
}
}
{
struct lustre_msg *msg = req->rq_reqbuf;
struct plain_header *phdr;
+ int swabbed;
ENTRY;
LASSERT(SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) ==
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");
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);
}
}
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;
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);