From d0dedfdc5217968757472168d4f32a608fcb8e9a Mon Sep 17 00:00:00 2001 From: bwzhou Date: Fri, 11 Jan 2008 10:54:09 +0000 Subject: [PATCH] Branch HEAD b=14043 r=adilger, umka This is used to determine the size of a buffer that was already packed and will correctly handle the different message formats. --- lustre/include/lustre_net.h | 1 + lustre/ptlrpc/pack_generic.c | 30 +++++++++++++++++++++++++++--- lustre/ptlrpc/ptlrpc_module.c | 1 + lustre/ptlrpc/sec_null.c | 9 +++------ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lustre/include/lustre_net.h b/lustre/include/lustre_net.h index 5baf93a..9e1a929 100644 --- a/lustre/include/lustre_net.h +++ b/lustre/include/lustre_net.h @@ -855,6 +855,7 @@ int lustre_shrink_msg(struct lustre_msg *msg, int segment, void lustre_free_reply_state(struct ptlrpc_reply_state *rs); int lustre_msg_size(__u32 magic, int count, int *lengths); int lustre_msg_size_v2(int count, int *lengths); +int lustre_packed_msg_size(struct lustre_msg *msg); int lustre_unpack_msg(struct lustre_msg *m, int len); void *lustre_msg_buf_v1(void *msg, int n, int min_size); void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size); diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index b561523..716f01e 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -110,7 +110,11 @@ int lustre_msg_size_v2(int count, int *lengths) EXPORT_SYMBOL(lustre_msg_size_v2); /* This returns the size of the buffer that is required to hold a lustre_msg - * with the given sub-buffer lengths. */ + * with the given sub-buffer lengths. + * NOTE: this should only be used for NEW requests, and should always be + * in the form of a v2 request. If this is a connection to a v1 + * target then the first buffer will be stripped because the ptlrpc + * data is part of the lustre_msg_v1 header. b=14043 */ int lustre_msg_size(__u32 magic, int count, int *lens) { int size[] = { sizeof(struct ptlrpc_body) }; @@ -134,6 +138,24 @@ int lustre_msg_size(__u32 magic, int count, int *lens) } } +/* This is used to determine the size of a buffer that was already packed + * and will correctly handle the different message formats. */ +int lustre_packed_msg_size(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: { + struct lustre_msg_v1 *v1_msg = (struct lustre_msg_v1 *)msg; + return lustre_msg_size_v1(v1_msg->lm_bufcount, + v1_msg->lm_buflens); + } + case LUSTRE_MSG_MAGIC_V2: + return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens); + default: + CERROR("incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + static void lustre_init_msg_v1(void *m, int count, int *lens, char **bufs) { @@ -765,16 +787,18 @@ static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m, { struct ptlrpc_body *pb; - pb = lustre_swab_buf(m, offset, sizeof(*pb), lustre_swab_ptlrpc_body); + pb = lustre_msg_buf_v2(m, offset, sizeof(*pb)); if (!pb) { CERROR("error unpacking ptlrpc body"); return -EFAULT; } + if (lustre_msg_swabbed(m)) + lustre_swab_ptlrpc_body(pb); if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) { CERROR("wrong lustre_msg version %08x\n", pb->pb_version); return -EINVAL; - } + } return 0; } diff --git a/lustre/ptlrpc/ptlrpc_module.c b/lustre/ptlrpc/ptlrpc_module.c index 65d986e..aa8db8c 100644 --- a/lustre/ptlrpc/ptlrpc_module.c +++ b/lustre/ptlrpc/ptlrpc_module.c @@ -204,6 +204,7 @@ EXPORT_SYMBOL(lustre_pack_reply); 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(lustre_msg_buf); EXPORT_SYMBOL(lustre_msg_string); diff --git a/lustre/ptlrpc/sec_null.c b/lustre/ptlrpc/sec_null.c index bee970b..2c86055 100644 --- a/lustre/ptlrpc/sec_null.c +++ b/lustre/ptlrpc/sec_null.c @@ -180,21 +180,18 @@ int null_enlarge_reqbuf(struct ptlrpc_sec *sec, int segment, int newsize) { struct lustre_msg *newbuf; + struct lustre_msg *oldbuf = req->rq_reqmsg; int oldsize, newmsg_size, alloc_size; LASSERT(req->rq_reqbuf); LASSERT(req->rq_reqbuf == req->rq_reqmsg); LASSERT(req->rq_reqbuf_len >= req->rq_reqlen); - LASSERT(req->rq_reqlen == lustre_msg_size(req->rq_reqmsg->lm_magic, - req->rq_reqmsg->lm_bufcount, - req->rq_reqmsg->lm_buflens)); + LASSERT(req->rq_reqlen == lustre_packed_msg_size(oldbuf)); /* compute new message size */ oldsize = req->rq_reqbuf->lm_buflens[segment]; req->rq_reqbuf->lm_buflens[segment] = newsize; - newmsg_size = lustre_msg_size(req->rq_reqbuf->lm_magic, - req->rq_reqbuf->lm_bufcount, - req->rq_reqbuf->lm_buflens); + newmsg_size = lustre_packed_msg_size(oldbuf); req->rq_reqbuf->lm_buflens[segment] = oldsize; /* request from pool should always have enough buffer */ -- 1.8.3.1