From 049f7b2a69005f9f3636dc54111fc24ac498ffb1 Mon Sep 17 00:00:00 2001 From: lsy Date: Mon, 15 May 2006 15:06:01 +0000 Subject: [PATCH] Land b1_5_msg_reorg(lustre msg v2) onto b1_5 (20060515_2228) --- lustre/include/lustre/lustre_idl.h | 125 +-- lustre/include/lustre_import.h | 23 +- lustre/include/lustre_net.h | 118 ++- lustre/include/obd.h | 2 +- lustre/ldlm/ldlm_lib.c | 84 +- lustre/ldlm/ldlm_lockd.c | 146 ++-- lustre/ldlm/ldlm_request.c | 87 +- lustre/liblustre/dir.c | 8 +- lustre/liblustre/file.c | 13 +- lustre/liblustre/namei.c | 4 +- lustre/liblustre/rw.c | 9 +- lustre/liblustre/super.c | 17 +- lustre/llite/dcache.c | 4 +- lustre/llite/dir.c | 67 +- lustre/llite/file.c | 27 +- lustre/llite/llite_lib.c | 10 +- lustre/llite/llite_nfs.c | 4 +- lustre/llite/namei.c | 42 +- lustre/llite/super25.c | 1 + lustre/llite/symlink.c | 24 +- lustre/llite/xattr.c | 20 +- lustre/mdc/mdc_internal.h | 6 +- lustre/mdc/mdc_lib.c | 20 +- lustre/mdc/mdc_locks.c | 137 ++-- lustre/mdc/mdc_reint.c | 78 +- lustre/mdc/mdc_request.c | 209 ++--- lustre/mds/handler.c | 204 ++--- lustre/mds/mds_internal.h | 6 +- lustre/mds/mds_join.c | 5 +- lustre/mds/mds_lib.c | 81 +- lustre/mds/mds_lov.c | 3 +- lustre/mds/mds_open.c | 109 +-- lustre/mds/mds_reint.c | 105 ++- lustre/mds/mds_xattr.c | 47 +- lustre/mgc/mgc_request.c | 13 +- lustre/mgs/mgs_handler.c | 23 +- lustre/obdclass/genops.c | 4 + lustre/obdclass/llog_lvfs.c | 6 +- lustre/obdclass/obd_mount.c | 3 +- lustre/obdfilter/filter.c | 13 +- lustre/osc/osc_create.c | 15 +- lustre/osc/osc_request.c | 442 +++++----- lustre/ost/lproc_ost.c | 4 +- lustre/ost/ost_handler.c | 258 +++--- lustre/ptlrpc/client.c | 111 ++- lustre/ptlrpc/import.c | 99 ++- lustre/ptlrpc/llog_client.c | 67 +- lustre/ptlrpc/llog_net.c | 13 +- lustre/ptlrpc/llog_server.c | 70 +- lustre/ptlrpc/lproc_ptlrpc.c | 6 +- lustre/ptlrpc/niobuf.c | 22 +- lustre/ptlrpc/pack_generic.c | 1565 ++++++++++++++++++++++++++++++------ lustre/ptlrpc/pinger.c | 8 +- lustre/ptlrpc/ptlrpc_module.c | 27 + lustre/ptlrpc/recov_thread.c | 15 +- lustre/ptlrpc/recover.c | 3 +- lustre/ptlrpc/service.c | 60 +- lustre/quota/quota_check.c | 23 +- lustre/quota/quota_context.c | 21 +- lustre/quota/quota_ctl.c | 17 +- lustre/tests/cfg/local.sh | 3 +- lustre/tests/sanity.sh | 2 +- lustre/utils/wirecheck.c | 72 +- lustre/utils/wiretest.c | 189 +++-- 64 files changed, 3302 insertions(+), 1717 deletions(-) diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 78012f4..bd60687 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -33,6 +33,8 @@ #ifndef _LUSTRE_IDL_H_ #define _LUSTRE_IDL_H_ +#include + #if defined(__linux__) #include #elif defined(__APPLE__) @@ -105,8 +107,14 @@ #define PTL_RPC_MSG_ERR 4712 #define PTL_RPC_MSG_REPLY 4713 -#define PTLRPC_MSG_MAGIC 0x0BD00BD0 +/* DON'T use swabbed values of MAGIC as magic! */ +#define LUSTRE_MSG_MAGIC_V1 0x0BD00BD0 +#define LUSTRE_MSG_MAGIC_V2 0x0BD00BD2 + +#define LUSTRE_MSG_MAGIC_V1_SWABBED 0xD00BD00B +#define LUSTRE_MSG_MAGIC_V2_SWABBED 0xD20BD00B +#define LUSTRE_MSG_MAGIC LUSTRE_MSG_MAGIC_V2 #define PTLRPC_MSG_VERSION 0x00000003 #define LUSTRE_VERSION_MASK 0xffff0000 @@ -142,22 +150,71 @@ static inline void lustre_handle_copy(struct lustre_handle *tgt, /* we depend on this structure to be 8-byte aligned */ /* this type is only endian-adjusted in lustre_unpack_msg() */ -struct lustre_msg { - struct lustre_handle handle; - __u32 magic; - __u32 type; - __u32 version; - __u32 opc; - __u64 last_xid; - __u64 last_committed; - __u64 transno; - __u32 status; - __u32 flags; - __u32 conn_cnt; - __u32 bufcount; - __u32 buflens[0]; +struct lustre_msg_v1 { + struct lustre_handle lm_handle; + __u32 lm_magic; + __u32 lm_type; + __u32 lm_version; + __u32 lm_opc; + __u64 lm_last_xid; + __u64 lm_last_committed; + __u64 lm_transno; + __u32 lm_status; + __u32 lm_flags; + __u32 lm_conn_cnt; + __u32 lm_bufcount; + __u32 lm_buflens[0]; +}; + +#define lustre_msg lustre_msg_v2 +/* we depend on this structure to be 8-byte aligned */ +/* this type is only endian-adjusted in lustre_unpack_msg() */ +struct lustre_msg_v2 { + __u32 lm_bufcount; + __u32 lm_secflvr; + __u32 lm_magic; + __u32 lm_repsize; + __u32 lm_buflens[0]; +}; + +/* without security, ptlrpc_body is put in the first buffer. */ +struct ptlrpc_body { + struct lustre_handle pb_handle; + __u32 pb_type; + __u32 pb_version; + __u32 pb_opc; + __u32 pb_status; + __u64 pb_last_xid; + __u64 pb_last_committed; + __u64 pb_transno; + __u32 pb_flags; + __u32 pb_op_flags; + __u32 pb_conn_cnt; + __u32 pb_paddings[3]; }; +extern void lustre_swab_ptlrpc_body(struct ptlrpc_body *pb); + +/* message body offset for lustre_msg_v2 */ +/* ptlrpc body offset in all request/reply messages */ +#define MSG_PTLRPC_BODY_OFF 0 + +/* normal request/reply message record offset */ +#define REQ_REC_OFF 1 +#define REPLY_REC_OFF 1 + +/* ldlm request message body offset */ +#define DLM_LOCKREQ_OFF 1 /* lockreq offset */ +#define DLM_REQ_REC_OFF 2 /* normal dlm request record offset */ + +/* ldlm intent lock message body offset */ +#define DLM_INTENT_IT_OFF 2 /* intent lock it offset */ +#define DLM_INTENT_REC_OFF 3 /* intent lock record offset */ + +/* ldlm reply message body offset */ +#define DLM_LOCKREPLY_OFF 1 /* lockrep offset */ +#define DLM_REPLY_REC_OFF 2 /* reply record offset */ + /* Flags that are operation-specific go in the top 16 bits. */ #define MSG_OP_FLAG_MASK 0xffff0000 #define MSG_OP_FLAG_SHIFT 16 @@ -168,43 +225,6 @@ struct lustre_msg { #define MSG_RESENT 2 #define MSG_REPLAY 4 -static inline int lustre_msg_get_flags(struct lustre_msg *msg) -{ - return (msg->flags & MSG_GEN_FLAG_MASK); -} - -static inline void lustre_msg_add_flags(struct lustre_msg *msg, int flags) -{ - msg->flags |= MSG_GEN_FLAG_MASK & flags; -} - -static inline void lustre_msg_set_flags(struct lustre_msg *msg, int flags) -{ - msg->flags &= ~MSG_GEN_FLAG_MASK; - lustre_msg_add_flags(msg, flags); -} - -static inline void lustre_msg_clear_flags(struct lustre_msg *msg, int flags) -{ - msg->flags &= ~(MSG_GEN_FLAG_MASK & flags); -} - -static inline int lustre_msg_get_op_flags(struct lustre_msg *msg) -{ - return (msg->flags >> MSG_OP_FLAG_SHIFT); -} - -static inline void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags) -{ - msg->flags |= ((flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT); -} - -static inline void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags) -{ - msg->flags &= ~MSG_OP_FLAG_MASK; - lustre_msg_add_op_flags(msg, flags); -} - /* * Flags for all connect opcodes (MDS_CONNECT, OST_CONNECT) */ @@ -216,6 +236,7 @@ static inline void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags) #define MSG_CONNECT_LIBCLIENT 0x10 #define MSG_CONNECT_INITIAL 0x20 #define MSG_CONNECT_ASYNC 0x40 +#define MSG_CONNECT_NEXT_VER 0x80 /* use next version of lustre_msg */ /* Connect flags */ #define OBD_CONNECT_RDONLY 0x1ULL /* client allowed read-only access */ diff --git a/lustre/include/lustre_import.h b/lustre/include/lustre_import.h index ff74277..f603c7f 100644 --- a/lustre/include/lustre_import.h +++ b/lustre/include/lustre_import.h @@ -86,21 +86,22 @@ struct obd_import { spinlock_t imp_lock; /* flags */ - unsigned int - imp_invalid:1, /* evicted */ - imp_replayable:1, /* try to recover the import */ - imp_dlm_fake:1, /* don't run recovery (timeout instead) */ - imp_server_timeout:1, /* use 1/2 timeout on MDS' OSCs */ - imp_initial_recov:1, /* retry the initial connection */ - imp_initial_recov_bk:1, /* turn off init_recov after trying all failover nids */ - imp_force_verify:1, /* force an immidiate ping */ - imp_pingable:1, /* pingable */ - imp_resend_replay:1, /* resend for replay */ - imp_deactive:1; /* administratively disabled */ + unsigned int imp_invalid:1, /* evicted */ + imp_replayable:1, /* try to recover the import */ + imp_dlm_fake:1, /* don't run recovery (timeout instead) */ + imp_server_timeout:1, /* use 1/2 timeout on MDS' OSCs */ + imp_initial_recov:1, /* retry the initial connection */ + imp_initial_recov_bk:1, /* turn off init_recov after trying all failover nids */ + imp_force_verify:1, /* force an immidiate ping */ + imp_pingable:1, /* pingable */ + imp_resend_replay:1, /* resend for replay */ + imp_deactive:1; /* administratively disabled */ __u32 imp_connect_op; struct obd_connect_data imp_connect_data; __u64 imp_connect_flags_orig; + __u32 imp_msg_magic; + struct ptlrpc_request_pool *imp_rq_pool; /* emergency request pool */ }; diff --git a/lustre/include/lustre_net.h b/lustre/include/lustre_net.h index bd596bf..e885c06 100644 --- a/lustre/include/lustre_net.h +++ b/lustre/include/lustre_net.h @@ -165,26 +165,27 @@ struct ptlrpc_client { /* unpacking: assert idx not unpacked already */ #define LASSERT_REQSWAB(rq, idx) \ do { \ - LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8); \ - LASSERT (((rq)->rq_req_swab_mask & (1 << (idx))) == 0); \ + LASSERT((idx) < sizeof((rq)->rq_req_swab_mask) * 8); \ + LASSERT(((rq)->rq_req_swab_mask & (1 << (idx))) == 0); \ (rq)->rq_req_swab_mask |= (1 << (idx)); \ } while (0) #define LASSERT_REPSWAB(rq, idx) \ do { \ - LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8); \ - LASSERT (((rq)->rq_rep_swab_mask & (1 << (idx))) == 0); \ + LASSERT((idx) < sizeof((rq)->rq_rep_swab_mask) * 8); \ + LASSERT(((rq)->rq_rep_swab_mask & (1 << (idx))) == 0); \ (rq)->rq_rep_swab_mask |= (1 << (idx)); \ } while (0) /* just looking: assert idx already unpacked */ -#define LASSERT_REQSWABBED(rq, idx) \ -LASSERT ((idx) < sizeof ((rq)->rq_req_swab_mask) * 8 && \ - ((rq)->rq_req_swab_mask & (1 << (idx))) != 0) +#define LASSERT_REQSWABBED(rq, idx) \ +LASSERT((idx) < sizeof((rq)->rq_req_swab_mask) * 8 && \ + ((rq)->rq_req_swab_mask & (1 << (idx))) != 0); \ + +#define LASSERT_REPSWABBED(rq, idx) \ +LASSERT((idx) < sizeof((rq)->rq_rep_swab_mask) * 8 && \ + ((rq)->rq_rep_swab_mask & (1 << (idx))) != 0); \ -#define LASSERT_REPSWABBED(rq, idx) \ -LASSERT ((idx) < sizeof ((rq)->rq_rep_swab_mask) * 8 && \ - ((rq)->rq_rep_swab_mask & (1 << (idx))) != 0) #else #define LASSERT_REQSWAB(rq, idx) #define LASSERT_REPSWAB(rq, idx) @@ -260,7 +261,7 @@ struct ptlrpc_reply_state { struct lustre_handle rs_locks[RS_MAX_LOCKS]; ldlm_mode_t rs_modes[RS_MAX_LOCKS]; /* last member: variable sized reply message */ - struct lustre_msg rs_msg; + struct lustre_msg *rs_msg; }; struct ptlrpc_thread; @@ -407,8 +408,8 @@ CDEB_TYPE(level, "@@@ " fmt \ " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl " \ REQ_FLAGS_FMT"/%x/%x rc %d/%d\n" , ## args, req, req->rq_xid, \ req->rq_transno, \ - req->rq_reqmsg ? req->rq_reqmsg->opc : -1, \ - req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) : "", \ + req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1, \ + req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) : "", \ req->rq_import ? \ (char *)req->rq_import->imp_connection->c_remote_uuid.uuid : "", \ (req->rq_import && req->rq_import->imp_client) ? \ @@ -416,9 +417,9 @@ CDEB_TYPE(level, "@@@ " fmt \ req->rq_reqlen, req->rq_replen, \ atomic_read(&req->rq_refcount), \ DEBUG_REQ_FLAGS(req), \ - req->rq_reqmsg ? req->rq_reqmsg->flags : 0, \ - req->rq_repmsg ? req->rq_repmsg->flags : 0, \ - req->rq_status, req->rq_repmsg ? req->rq_repmsg->status : 0) + req->rq_reqmsg ? lustre_msg_get_flags(req->rq_reqmsg) : 0, \ + req->rq_repmsg ? lustre_msg_get_flags(req->rq_repmsg) : 0, \ + req->rq_status, req->rq_repmsg ? lustre_msg_get_status(req->rq_repmsg) : 0) /* for most callers (level is a constant) this is resolved at compile time */ #define DEBUG_REQ(level, req, fmt, args...) \ @@ -674,11 +675,11 @@ void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq); struct ptlrpc_request_pool *ptlrpc_init_rq_pool(int, int, void (*populate_pool)(struct ptlrpc_request_pool *, int)); struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version, - int opcode, int count, - int *lengths, char **bufs); -struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp, __u32 version, - int opcode, int count, int *lengths, - char **bufs, + int opcode, int count, int *lengths, + char **bufs); +struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp, + __u32 version, int opcode, + int count, int *lengths, char **bufs, struct ptlrpc_request_pool *pool); void ptlrpc_free_req(struct ptlrpc_request *request); void ptlrpc_req_finished(struct ptlrpc_request *request); @@ -737,23 +738,52 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp); /* ptlrpc/pack_generic.c */ int lustre_msg_swabbed(struct lustre_msg *msg); int lustre_msg_check_version(struct lustre_msg *msg, __u32 version); -int lustre_pack_request(struct ptlrpc_request *, int count, int *lens, - char **bufs); +int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count, + int *lens, char **bufs); int lustre_pack_reply(struct ptlrpc_request *, int count, int *lens, char **bufs); -void lustre_shrink_reply(struct ptlrpc_request *req, - int segment, unsigned int newlen, int move_data); +void lustre_shrink_reply(struct ptlrpc_request *req, int segment, + unsigned int newlen, int move_data); void lustre_free_reply_state(struct ptlrpc_reply_state *rs); -int lustre_msg_size(int count, int *lengths); +int lustre_msg_size(__u32 magic, int count, int *lengths); int lustre_unpack_msg(struct lustre_msg *m, int len); +int lustre_unpack_ptlrpc_body(struct lustre_msg *m); 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, - 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, + void *swabber); +__u32 lustre_msg_get_flags(struct lustre_msg *msg); +void lustre_msg_add_flags(struct lustre_msg *msg, int flags); +void lustre_msg_set_flags(struct lustre_msg *msg, int flags); +void lustre_msg_clear_flags(struct lustre_msg *msg, int flags); +__u32 lustre_msg_get_op_flags(struct lustre_msg *msg); +void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags); +void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags); +struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg); +__u32 lustre_msg_get_type(struct lustre_msg *msg); +__u32 lustre_msg_get_version(struct lustre_msg *msg); +void lustre_msg_add_version(struct lustre_msg *msg, int version); +__u32 lustre_msg_get_opc(struct lustre_msg *msg); +__u64 lustre_msg_get_last_xid(struct lustre_msg *msg); +__u64 lustre_msg_get_last_committed(struct lustre_msg *msg); +__u64 lustre_msg_get_transno(struct lustre_msg *msg); +__u32 lustre_msg_get_status(struct lustre_msg *msg); +__u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg); +__u32 lustre_msg_get_magic(struct lustre_msg *msg); +void lustre_msg_set_handle(struct lustre_msg *msg,struct lustre_handle *handle); +void lustre_msg_set_type(struct lustre_msg *msg, __u32 type); +void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc); +void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid); +void lustre_msg_set_last_committed(struct lustre_msg *msg,__u64 last_committed); +void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno); +void lustre_msg_set_status(struct lustre_msg *msg, __u32 status); +void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt); static inline void ptlrpc_rs_addref(struct ptlrpc_reply_state *rs) @@ -770,6 +800,34 @@ ptlrpc_rs_decref(struct ptlrpc_reply_state *rs) lustre_free_reply_state(rs); } +static inline __u32 lustre_request_magic(struct ptlrpc_request *req) +{ + return lustre_msg_get_magic(req->rq_reqmsg); +} + +static inline int ptlrpc_req_get_repsize(struct ptlrpc_request *req) +{ + switch (req->rq_reqmsg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + CERROR("function not supported for lustre_msg V1!\n"); + return -ENOTSUPP; + case LUSTRE_MSG_MAGIC_V2: + return req->rq_reqmsg->lm_repsize; + default: + LASSERTF(0, "incorrect message magic: %08x\n", + req->rq_reqmsg->lm_magic); + return -EFAULT; + } +} + +static inline void +ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, int *lens) +{ + req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens); + if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2) + req->rq_reqmsg->lm_repsize = req->rq_replen; +} + /* ldlm/ldlm_lib.c */ int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf); int client_obd_cleanup(struct obd_device * obddev); diff --git a/lustre/include/obd.h b/lustre/include/obd.h index cc5b5bd..feb2b49 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -585,7 +585,7 @@ static inline void oti_init(struct obd_trans_info *oti, return; if (req->rq_repmsg && req->rq_reqmsg != 0) - oti->oti_transno = req->rq_repmsg->transno; + oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg); oti->oti_thread_id = req->rq_svc_thread ? req->rq_svc_thread->t_id : -1; } diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index fd3fa69..a5e1e86 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -523,13 +523,13 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler) int rc = 0, abort_recovery; unsigned long flags; struct obd_connect_data *data; - int size = sizeof(*data); + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*data) }; ENTRY; OBD_RACE(OBD_FAIL_TGT_CONN_RACE); - LASSERT_REQSWAB (req, 0); - str = lustre_msg_string(req->rq_reqmsg, 0, sizeof(tgtuuid) - 1); + LASSERT_REQSWAB(req, REQ_REC_OFF); + str = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF, sizeof(tgtuuid)-1); if (str == NULL) { DEBUG_REQ(D_ERROR, req, "bad target UUID for connect"); GOTO(out, rc = -EINVAL); @@ -561,8 +561,9 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler) Really, class_uuid2obd should take the ref. */ targref = class_incref(target); - LASSERT_REQSWAB (req, 1); - str = lustre_msg_string(req->rq_reqmsg, 1, sizeof(cluuid) - 1); + LASSERT_REQSWAB(req, REQ_REC_OFF + 1); + str = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1, + sizeof(cluuid) - 1); if (str == NULL) { DEBUG_REQ(D_ERROR, req, "bad client UUID for connect"); GOTO(out, rc = -EINVAL); @@ -591,14 +592,15 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler) if (abort_recovery) target_abort_recovery(target); - tmp = lustre_msg_buf(req->rq_reqmsg, 2, sizeof conn); + tmp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof conn); if (tmp == NULL) GOTO(out, rc = -EPROTO); memcpy(&conn, tmp, sizeof conn); - data = lustre_swab_reqbuf(req, 3, sizeof(*data), lustre_swab_connect); - rc = lustre_pack_reply(req, 1, &size, NULL); + data = lustre_swab_reqbuf(req, REQ_REC_OFF + 3, sizeof(*data), + lustre_swab_connect); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) GOTO(out, rc); @@ -655,7 +657,7 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler) if (!export) { spin_unlock(&target->obd_dev_lock); OBD_FAIL_TIMEOUT(OBD_FAIL_TGT_DELAY_CONNECT, 2 * obd_timeout); - } else if (req->rq_reqmsg->conn_cnt == 1) { + } else if (lustre_msg_get_conn_cnt(req->rq_reqmsg) == 1) { CERROR("%s: NID %s (%s) reconnected with 1 conn_cnt; " "cookies not random?\n", target->obd_name, libcfs_nid2str(req->rq_peer.nid), cluuid.uuid); @@ -708,13 +710,14 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler) /* Return only the parts of obd_connect_data that we understand, so the * client knows that we don't understand the rest. */ if (data) - memcpy(lustre_msg_buf(req->rq_repmsg, 0, sizeof(*data)), data, - sizeof(*data)); + memcpy(lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*data)), + data, sizeof(*data)); /* If all else goes well, this is our RPC return code. */ req->rq_status = 0; - req->rq_repmsg->handle = conn; + lustre_msg_set_handle(req->rq_repmsg, &conn); /* ownership of this export ref transfers to the request AFTER we * drop any previous reference the request had, but we don't want @@ -739,14 +742,16 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler) req->rq_export = export; spin_lock_irqsave(&export->exp_lock, flags); - if (export->exp_conn_cnt >= req->rq_reqmsg->conn_cnt) { + if (export->exp_conn_cnt >= lustre_msg_get_conn_cnt(req->rq_reqmsg)) { CERROR("%s: %s already connected at higher conn_cnt: %d > %d\n", cluuid.uuid, libcfs_nid2str(req->rq_peer.nid), - export->exp_conn_cnt, req->rq_reqmsg->conn_cnt); + export->exp_conn_cnt, + lustre_msg_get_conn_cnt(req->rq_reqmsg)); + spin_unlock_irqrestore(&export->exp_lock, flags); GOTO(out, rc = -EALREADY); } - export->exp_conn_cnt = req->rq_reqmsg->conn_cnt; + export->exp_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg); spin_unlock_irqrestore(&export->exp_lock, flags); /* request from liblustre? Don't evict it for not pinging. */ @@ -769,7 +774,8 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler) if (target->obd_recovering) target->obd_connected_clients++; - memcpy(&conn, lustre_msg_buf(req->rq_reqmsg, 2, sizeof conn), + memcpy(&conn, + lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof conn), sizeof conn); if (export->exp_imp_reverse != NULL) @@ -780,6 +786,12 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler) revimp->imp_remote_handle = conn; revimp->imp_dlm_fake = 1; revimp->imp_state = LUSTRE_IMP_FULL; + + if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_NEXT_VER) { + revimp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2; + lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_NEXT_VER); + } + class_import_put(revimp); out: if (export) @@ -796,7 +808,7 @@ int target_handle_disconnect(struct ptlrpc_request *req) int rc; ENTRY; - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) RETURN(rc); @@ -874,7 +886,7 @@ static void abort_recovery_queue(struct obd_device *obd) DEBUG_REQ(D_ERROR, req, "aborted:"); req->rq_status = -ENOTCONN; req->rq_type = PTL_RPC_MSG_ERR; - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc == 0) { ptlrpc_reply(req); } else { @@ -1016,7 +1028,7 @@ static int check_for_next_transno(struct obd_device *obd) req = list_entry(obd->obd_recovery_queue.next, struct ptlrpc_request, rq_list); max = obd->obd_max_recoverable_clients; - req_transno = req->rq_reqmsg->transno; + req_transno = lustre_msg_get_transno(req->rq_reqmsg); connected = obd->obd_connected_clients; completed = max - obd->obd_recoverable_clients; queue_len = obd->obd_requests_queued_for_recovery; @@ -1043,7 +1055,7 @@ static int check_for_next_transno(struct obd_device *obd) wake_up = 1; } spin_unlock_bh(&obd->obd_processing_task_lock); - LASSERT(req->rq_reqmsg->transno >= next_transno); + LASSERT(lustre_msg_get_transno(req->rq_reqmsg) >= next_transno); return wake_up; } @@ -1060,12 +1072,13 @@ static void process_recovery_queue(struct obd_device *obd) req = list_entry(obd->obd_recovery_queue.next, struct ptlrpc_request, rq_list); - if (req->rq_reqmsg->transno != obd->obd_next_recovery_transno) { + if (lustre_msg_get_transno(req->rq_reqmsg) != + obd->obd_next_recovery_transno) { spin_unlock_bh(&obd->obd_processing_task_lock); CDEBUG(D_HA, "Waiting for transno "LPD64" (1st is " LPD64")\n", obd->obd_next_recovery_transno, - req->rq_reqmsg->transno); + lustre_msg_get_transno(req->rq_reqmsg)); l_wait_event(obd->obd_next_transno_waitq, check_for_next_transno(obd), &lwi); spin_lock_bh(&obd->obd_processing_task_lock); @@ -1111,7 +1124,7 @@ int target_queue_recovery_request(struct ptlrpc_request *req, { struct list_head *tmp; int inserted = 0; - __u64 transno = req->rq_reqmsg->transno; + __u64 transno = lustre_msg_get_transno(req->rq_reqmsg); struct ptlrpc_request *saved_req; struct lustre_msg *reqmsg; @@ -1179,7 +1192,7 @@ int target_queue_recovery_request(struct ptlrpc_request *req, struct ptlrpc_request *reqiter = list_entry(tmp, struct ptlrpc_request, rq_list); - if (reqiter->rq_reqmsg->transno > transno) { + if (lustre_msg_get_transno(reqiter->rq_reqmsg) > transno) { list_add_tail(&req->rq_list, &reqiter->rq_list); inserted = 1; break; @@ -1227,7 +1240,7 @@ int target_queue_final_reply(struct ptlrpc_request *req, int rc) if (rc) { /* Just like ptlrpc_error, but without the sending. */ - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); LASSERT(rc == 0); /* XXX handle this */ req->rq_type = PTL_RPC_MSG_ERR; } @@ -1396,7 +1409,7 @@ target_send_reply(struct ptlrpc_request *req, int rc, int fail_id) int target_handle_ping(struct ptlrpc_request *req) { - return lustre_pack_reply(req, 0, NULL, NULL); + return lustre_pack_reply(req, 1, NULL, NULL); } void target_committed_to_req(struct ptlrpc_request *req) @@ -1404,7 +1417,8 @@ void target_committed_to_req(struct ptlrpc_request *req) struct obd_device *obd = req->rq_export->exp_obd; if (!obd->obd_no_transno && req->rq_repmsg != NULL) - req->rq_repmsg->last_committed = obd->obd_last_committed; + lustre_msg_set_last_committed(req->rq_repmsg, + obd->obd_last_committed); else DEBUG_REQ(D_IOCTL, req, "not sending last_committed update"); @@ -1420,7 +1434,7 @@ int target_handle_qc_callback(struct ptlrpc_request *req) struct obd_quotactl *oqctl; struct client_obd *cli = &req->rq_export->exp_obd->u.cli; - oqctl = lustre_swab_reqbuf(req, 0, sizeof(*oqctl), + oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl), lustre_swab_obd_quotactl); cli->cl_qchk_stat = oqctl->qc_stat; @@ -1435,18 +1449,21 @@ int target_handle_dqacq_callback(struct ptlrpc_request *req) struct obd_device *master_obd; struct lustre_quota_ctxt *qctxt; struct qunit_data *qdata, *rep; - int rc = 0, repsize = sizeof(struct qunit_data); + int rc = 0; + int repsize[2] = { sizeof(struct ptlrpc_body), + sizeof(struct qunit_data) }; ENTRY; - rc = lustre_pack_reply(req, 1, &repsize, NULL); + rc = lustre_pack_reply(req, 2, repsize, NULL); if (rc) { CERROR("packing reply failed!: rc = %d\n", rc); RETURN(rc); } - rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep)); + rep = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*rep)); LASSERT(rep); - qdata = lustre_swab_reqbuf(req, 0, sizeof(*qdata), lustre_swab_qdata); + qdata = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*qdata), + lustre_swab_qdata); if (qdata == NULL) { CERROR("unpacking request buffer failed!"); RETURN(-EPROTO); @@ -1458,7 +1475,8 @@ int target_handle_dqacq_callback(struct ptlrpc_request *req) qctxt = &master_obd->u.obt.obt_qctxt; LASSERT(qctxt->lqc_handler); - rc = qctxt->lqc_handler(master_obd, qdata, req->rq_reqmsg->opc); + rc = qctxt->lqc_handler(master_obd, qdata, + lustre_msg_get_opc(req->rq_reqmsg)); if (rc && rc != -EDQUOT) CDEBUG(rc == -EBUSY ? D_QUOTA : D_ERROR, "dqacq failed! (rc:%d)\n", rc); diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c index 410e438..321e578 100644 --- a/lustre/ldlm/ldlm_lockd.c +++ b/lustre/ldlm/ldlm_lockd.c @@ -451,12 +451,14 @@ static int ldlm_handle_ast_error(struct ldlm_lock *lock, LDLM_DEBUG(lock, "client (nid %s) returned %d" " from %s AST - normal race", libcfs_nid2str(peer.nid), - req->rq_repmsg->status, ast_type); + lustre_msg_get_status(req->rq_repmsg), + ast_type); else LDLM_ERROR(lock, "client (nid %s) returned %d " "from %s AST", libcfs_nid2str(peer.nid), (req->rq_repmsg != NULL) ? - req->rq_repmsg->status : 0, ast_type); + lustre_msg_get_status(req->rq_repmsg) : 0, + ast_type); ldlm_lock_cancel(lock); l_unlock(&lock->l_resource->lr_namespace->ns_lock); /* Server-side AST functions are called from ldlm_reprocess_all, @@ -473,8 +475,9 @@ int ldlm_server_blocking_ast(struct ldlm_lock *lock, { struct ldlm_request *body; struct ptlrpc_request *req; - int rc = 0, size = sizeof(*body); - int instant_cancel = 0; + int size[] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREQ_OFF] = sizeof(*body) }; + int instant_cancel = 0, rc = 0; ENTRY; if (flag == LDLM_CB_CANCELING) { @@ -511,20 +514,20 @@ int ldlm_server_blocking_ast(struct ldlm_lock *lock, instant_cancel = 1; req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse, - LUSTRE_DLM_VERSION, LDLM_BL_CALLBACK, - 1, &size, NULL); + LUSTRE_DLM_VERSION, LDLM_BL_CALLBACK, 2, size, + NULL); if (req == NULL) { l_unlock(&lock->l_resource->lr_namespace->ns_lock); RETURN(-ENOMEM); } - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, sizeof(*body)); body->lock_handle1 = lock->l_remote_handle; body->lock_desc = *desc; body->lock_flags |= (lock->l_flags & LDLM_AST_FLAGS); LDLM_DEBUG(lock, "server preparing blocking AST"); - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); if (instant_cancel) ldlm_lock_cancel(lock); else if (lock->l_granted_mode == lock->l_req_mode) @@ -557,7 +560,9 @@ int ldlm_server_completion_ast(struct ldlm_lock *lock, int flags, void *data) struct ptlrpc_request *req; struct timeval granted_time; long total_enqueue_wait; - int rc = 0, size[2] = {sizeof(*body)}, buffers = 1, instant_cancel = 0; + int size[3] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREQ_OFF] = sizeof(*body) }; + int rc = 0, buffers = 2, instant_cancel = 0; ENTRY; LASSERT(lock != NULL); @@ -572,27 +577,27 @@ int ldlm_server_completion_ast(struct ldlm_lock *lock, int flags, void *data) mutex_down(&lock->l_resource->lr_lvb_sem); if (lock->l_resource->lr_lvb_len) { - buffers = 2; - size[1] = lock->l_resource->lr_lvb_len; + size[DLM_REQ_REC_OFF] = lock->l_resource->lr_lvb_len; + buffers = 3; } mutex_up(&lock->l_resource->lr_lvb_sem); req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse, - LUSTRE_DLM_VERSION, LDLM_CP_CALLBACK, - buffers, size, NULL); + LUSTRE_DLM_VERSION, LDLM_CP_CALLBACK, buffers, + size, NULL); if (req == NULL) RETURN(-ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, sizeof(*body)); body->lock_handle1 = lock->l_remote_handle; body->lock_flags = flags; ldlm_lock2desc(lock, &body->lock_desc); - if (buffers == 2) { + if (buffers == 3) { void *lvb; mutex_down(&lock->l_resource->lr_lvb_sem); - lvb = lustre_msg_buf(req->rq_reqmsg, 1, + lvb = lustre_msg_buf(req->rq_reqmsg, DLM_REQ_REC_OFF, lock->l_resource->lr_lvb_len); memcpy(lvb, lock->l_resource->lr_lvb_data, lock->l_resource->lr_lvb_len); @@ -601,7 +606,7 @@ int ldlm_server_completion_ast(struct ldlm_lock *lock, int flags, void *data) LDLM_DEBUG(lock, "server preparing completion AST (after %ldus wait)", total_enqueue_wait); - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); req->rq_send_state = LUSTRE_IMP_FULL; req->rq_timeout = ldlm_timeout; /* timeout for initial AST reply */ @@ -645,25 +650,27 @@ int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data) struct ldlm_resource *res = lock->l_resource; struct ldlm_request *body; struct ptlrpc_request *req; - int rc = 0, size = sizeof(*body); + int size[] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREQ_OFF] = sizeof(*body) }; + int rc = 0; ENTRY; LASSERT(lock != NULL); req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse, - LUSTRE_DLM_VERSION, LDLM_GL_CALLBACK, - 1, &size, NULL); + LUSTRE_DLM_VERSION, LDLM_GL_CALLBACK, 2, size, + NULL); if (req == NULL) RETURN(-ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, sizeof(*body)); body->lock_handle1 = lock->l_remote_handle; ldlm_lock2desc(lock, &body->lock_desc); mutex_down(&lock->l_resource->lr_lvb_sem); - size = lock->l_resource->lr_lvb_len; + size[REPLY_REC_OFF] = lock->l_resource->lr_lvb_len; mutex_up(&lock->l_resource->lr_lvb_sem); - req->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); req->rq_send_state = LUSTRE_IMP_FULL; req->rq_timeout = ldlm_timeout; /* timeout for initial AST reply */ @@ -675,7 +682,7 @@ int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data) rc = ldlm_handle_ast_error(lock, req, rc, "glimpse"); else rc = res->lr_namespace->ns_lvbo->lvbo_update - (res, req->rq_repmsg, 0, 1); + (res, req->rq_repmsg, REPLY_REC_OFF, 1); ptlrpc_req_finished(req); RETURN(rc); } @@ -713,7 +720,9 @@ int ldlm_handle_enqueue(struct ptlrpc_request *req, struct obd_device *obddev = req->rq_export->exp_obd; struct ldlm_reply *dlm_rep; struct ldlm_request *dlm_req; - int rc = 0, size[2] = {sizeof(*dlm_rep)}; + int size[3] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREPLY_OFF] = sizeof(*dlm_rep) }; + int rc = 0; __u32 flags; ldlm_error_t err = ELDLM_OK; struct ldlm_lock *lock = NULL; @@ -722,9 +731,8 @@ int ldlm_handle_enqueue(struct ptlrpc_request *req, LDLM_DEBUG_NOLOCK("server-side enqueue handler START"); - dlm_req = lustre_swab_reqbuf (req, MDS_REQ_INTENT_LOCKREQ_OFF, - sizeof (*dlm_req), - lustre_swab_ldlm_request); + dlm_req = lustre_swab_reqbuf(req, DLM_LOCKREQ_OFF, sizeof(*dlm_req), + lustre_swab_ldlm_request); if (dlm_req == NULL) { CERROR ("Can't unpack dlm_req\n"); GOTO(out, rc = -EFAULT); @@ -823,12 +831,12 @@ existing_lock: * local_lock_enqueue by the policy function. */ cookie = req; } else { - int buffers = 1; + int buffers = 2; mutex_down(&lock->l_resource->lr_lvb_sem); if (lock->l_resource->lr_lvb_len) { - size[1] = lock->l_resource->lr_lvb_len; - buffers = 2; + size[DLM_REPLY_REC_OFF] = lock->l_resource->lr_lvb_len; + buffers = 3; } mutex_up(&lock->l_resource->lr_lvb_sem); @@ -849,7 +857,8 @@ existing_lock: if (err) GOTO(out, err); - dlm_rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*dlm_rep)); + dlm_rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, + sizeof(*dlm_rep)); dlm_rep->lock_flags = flags; ldlm_lock2desc(lock, &dlm_rep->lock_desc); @@ -891,11 +900,11 @@ existing_lock: LDLM_ERROR(lock, "sync lock"); if (dlm_req->lock_flags & LDLM_FL_HAS_INTENT) { struct ldlm_intent *it; - it = lustre_msg_buf(req->rq_reqmsg, 1, + it = lustre_msg_buf(req->rq_reqmsg, + DLM_INTENT_IT_OFF, sizeof(*it)); if (it != NULL) { - CERROR("This is intent %s (" - LPU64 ")\n", + CERROR("This is intent %s ("LPU64")\n", ldlm_it2str(it->opc), it->opc); } } @@ -908,7 +917,7 @@ existing_lock: out: req->rq_status = err; if (req->rq_reply_state == NULL) { - err = lustre_pack_reply(req, 0, NULL, NULL); + err = lustre_pack_reply(req, 1, NULL, NULL); if (rc == 0) rc = err; req->rq_status = rc; @@ -924,15 +933,16 @@ existing_lock: if (rc == 0) { mutex_down(&lock->l_resource->lr_lvb_sem); - size[1] = lock->l_resource->lr_lvb_len; - if (size[1] > 0) { + size[DLM_REPLY_REC_OFF] = lock->l_resource->lr_lvb_len; + if (size[DLM_REPLY_REC_OFF] > 0) { void *lvb = lustre_msg_buf(req->rq_repmsg, - 1, size[1]); + DLM_REPLY_REC_OFF, + size[DLM_REPLY_REC_OFF]); LASSERTF(lvb != NULL, "req %p, lock %p\n", req, lock); memcpy(lvb, lock->l_resource->lr_lvb_data, - size[1]); + size[DLM_REPLY_REC_OFF]); } mutex_up(&lock->l_resource->lr_lvb_sem); } else { @@ -957,22 +967,25 @@ int ldlm_handle_convert(struct ptlrpc_request *req) struct ldlm_request *dlm_req; struct ldlm_reply *dlm_rep; struct ldlm_lock *lock; - int rc, size = sizeof(*dlm_rep); + int rc; + int size[2] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREPLY_OFF] = sizeof(*dlm_rep) }; ENTRY; - dlm_req = lustre_swab_reqbuf (req, 0, sizeof (*dlm_req), - lustre_swab_ldlm_request); + dlm_req = lustre_swab_reqbuf(req, DLM_LOCKREQ_OFF, sizeof(*dlm_req), + lustre_swab_ldlm_request); if (dlm_req == NULL) { CERROR ("Can't unpack dlm_req\n"); RETURN (-EFAULT); } - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) { CERROR("out of memory\n"); RETURN(-ENOMEM); } - dlm_rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*dlm_rep)); + dlm_rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, + sizeof(*dlm_rep)); dlm_rep->lock_flags = dlm_req->lock_flags; lock = ldlm_handle2lock(&dlm_req->lock_handle1); @@ -1019,14 +1032,14 @@ int ldlm_handle_cancel(struct ptlrpc_request *req) int rc; ENTRY; - dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req), - lustre_swab_ldlm_request); + dlm_req = lustre_swab_reqbuf(req, DLM_LOCKREQ_OFF, sizeof(*dlm_req), + lustre_swab_ldlm_request); if (dlm_req == NULL) { CERROR("bad request buffer for cancel\n"); RETURN(-EFAULT); } - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) { CERROR("out of memory\n"); RETURN(-ENOMEM); @@ -1153,7 +1166,7 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req, if (lock->l_lvb_len) { void *lvb; - lvb = lustre_swab_reqbuf(req, 1, lock->l_lvb_len, + lvb = lustre_swab_reqbuf(req, DLM_REQ_REC_OFF, lock->l_lvb_len, lock->l_lvb_swabber); if (lvb == NULL) { LDLM_ERROR(lock, "completion AST did not contain " @@ -1221,7 +1234,7 @@ static int ldlm_callback_reply(struct ptlrpc_request *req, int rc) { req->rq_status = rc; if (req->rq_reply_state == NULL) { - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) return rc; } @@ -1275,11 +1288,12 @@ static int ldlm_callback_handler(struct ptlrpc_request *req) CDEBUG(D_RPCTRACE, "operation %d from %s with bad " "export cookie "LPX64"; this is " "normal if this node rebooted with a lock held\n", - req->rq_reqmsg->opc, + lustre_msg_get_opc(req->rq_reqmsg), libcfs_id2str(req->rq_peer), - req->rq_reqmsg->handle.cookie); + lustre_msg_get_handle(req->rq_reqmsg)->cookie); - dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req), + dlm_req = lustre_swab_reqbuf(req, DLM_LOCKREQ_OFF, + sizeof(*dlm_req), lustre_swab_ldlm_request); if (dlm_req != NULL) CDEBUG(D_RPCTRACE, "--> lock cookie: "LPX64"\n", @@ -1292,7 +1306,7 @@ static int ldlm_callback_handler(struct ptlrpc_request *req) LASSERT(req->rq_export != NULL); LASSERT(req->rq_export->exp_obd != NULL); - switch(req->rq_reqmsg->opc) { + switch (lustre_msg_get_opc(req->rq_reqmsg)) { case LDLM_BL_CALLBACK: OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0); break; @@ -1338,7 +1352,8 @@ static int ldlm_callback_handler(struct ptlrpc_request *req) ldlm_callback_reply(req, rc); RETURN(0); default: - CERROR("unknown opcode %u\n", req->rq_reqmsg->opc); + CERROR("unknown opcode %u\n", + lustre_msg_get_opc(req->rq_reqmsg)); ldlm_callback_reply(req, -EPROTO); RETURN(0); } @@ -1346,11 +1361,11 @@ static int ldlm_callback_handler(struct ptlrpc_request *req) ns = req->rq_export->exp_obd->obd_namespace; LASSERT(ns != NULL); - dlm_req = lustre_swab_reqbuf (req, 0, sizeof (*dlm_req), - lustre_swab_ldlm_request); + dlm_req = lustre_swab_reqbuf(req, DLM_LOCKREQ_OFF, sizeof(*dlm_req), + lustre_swab_ldlm_request); if (dlm_req == NULL) { CERROR ("can't unpack dlm_req\n"); - ldlm_callback_reply (req, -EPROTO); + ldlm_callback_reply(req, -EPROTO); RETURN (0); } @@ -1374,7 +1389,7 @@ static int ldlm_callback_handler(struct ptlrpc_request *req) * in the reply, so we might have to push the responsibility for sending * the reply down into the AST handlers, alas. */ - switch (req->rq_reqmsg->opc) { + switch (lustre_msg_get_opc(req->rq_reqmsg)) { case LDLM_BL_CALLBACK: CDEBUG(D_INODE, "blocking ast\n"); if (!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)) @@ -1412,10 +1427,12 @@ static int ldlm_cancel_handler(struct ptlrpc_request *req) struct ldlm_request *dlm_req; CERROR("operation %d from %s with bad export cookie "LPU64"\n", - req->rq_reqmsg->opc, libcfs_id2str(req->rq_peer), - req->rq_reqmsg->handle.cookie); + lustre_msg_get_opc(req->rq_reqmsg), + libcfs_id2str(req->rq_peer), + lustre_msg_get_handle(req->rq_reqmsg)->cookie); - dlm_req = lustre_swab_reqbuf(req, 0, sizeof (*dlm_req), + dlm_req = lustre_swab_reqbuf(req, DLM_LOCKREQ_OFF, + sizeof(*dlm_req), lustre_swab_ldlm_request); if (dlm_req != NULL) ldlm_lock_dump_handle(D_ERROR, &dlm_req->lock_handle1); @@ -1424,7 +1441,7 @@ static int ldlm_cancel_handler(struct ptlrpc_request *req) RETURN(0); } - switch (req->rq_reqmsg->opc) { + switch (lustre_msg_get_opc(req->rq_reqmsg)) { /* XXX FIXME move this back to mds/handler.c, bug 249 */ case LDLM_CANCEL: @@ -1440,7 +1457,8 @@ static int ldlm_cancel_handler(struct ptlrpc_request *req) ldlm_callback_reply(req, rc); RETURN(0); default: - CERROR("invalid opcode %d\n", req->rq_reqmsg->opc); + CERROR("invalid opcode %d\n", + lustre_msg_get_opc(req->rq_reqmsg)); ldlm_callback_reply(req, -EINVAL); } diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c index a849a31..21eee08 100644 --- a/lustre/ldlm/ldlm_request.c +++ b/lustre/ldlm/ldlm_request.c @@ -321,9 +321,11 @@ int ldlm_cli_enqueue(struct obd_export *exp, struct ldlm_lock *lock; struct ldlm_request *body; struct ldlm_reply *reply; - int rc, size[] = {sizeof(*body), lvb_len}, req_passed_in = 1; + int size[3] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREQ_OFF] = sizeof(*body), + [DLM_REPLY_REC_OFF] = lvb_len }; int is_replay = *flags & LDLM_FL_REPLAY; - int cleanup_phase = 0; + int req_passed_in = 1, cleanup_phase = 0, rc; ENTRY; if (exp == NULL) { @@ -375,16 +377,16 @@ int ldlm_cli_enqueue(struct obd_export *exp, if (req == NULL) { req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION, - LDLM_ENQUEUE, 1, size, NULL); + LDLM_ENQUEUE, 2, size, NULL); if (req == NULL) GOTO(cleanup, rc = -ENOMEM); req_passed_in = 0; } else { - LASSERTF(req->rq_reqmsg->buflens[MDS_REQ_INTENT_LOCKREQ_OFF] == + LASSERTF(lustre_msg_buflen(req->rq_reqmsg, DLM_LOCKREQ_OFF) == sizeof(*body), "buflen[%d] = %d, not %d\n", - MDS_REQ_INTENT_LOCKREQ_OFF, - req->rq_reqmsg->buflens[MDS_REQ_INTENT_LOCKREQ_OFF], - (int)sizeof(*body)); + DLM_LOCKREQ_OFF, + lustre_msg_buflen(req->rq_reqmsg, DLM_LOCKREQ_OFF), + sizeof(*body)); } lock->l_conn_export = exp; @@ -392,17 +394,16 @@ int ldlm_cli_enqueue(struct obd_export *exp, lock->l_blocking_ast = blocking; /* Dump lock data into the request buffer */ - body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_INTENT_LOCKREQ_OFF, - sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, sizeof(*body)); ldlm_lock2desc(lock, &body->lock_desc); body->lock_flags = *flags; - body->lock_handle1 = *lockh; /* Continue as normal. */ if (!req_passed_in) { - size[0] = sizeof(*reply); - req->rq_replen = lustre_msg_size(1 + (lvb_len > 0), size); + size[DLM_LOCKREPLY_OFF] = sizeof(*reply); + ptlrpc_req_set_repsize(req, 2 + (lvb_len > 0), size); + } LDLM_DEBUG(lock, "sending request"); rc = ptlrpc_queue_wait(req); @@ -413,7 +414,8 @@ int ldlm_cli_enqueue(struct obd_export *exp, rc == ELDLM_LOCK_ABORTED ? "ABORTED" : "FAILED"); if (rc == ELDLM_LOCK_ABORTED) { /* Before we return, swab the reply */ - reply = lustre_swab_repbuf(req, 0, sizeof(*reply), + reply = lustre_swab_repbuf(req, DLM_LOCKREPLY_OFF, + sizeof(*reply), lustre_swab_ldlm_reply); if (reply == NULL) { CERROR("Can't unpack ldlm_reply\n"); @@ -421,7 +423,9 @@ int ldlm_cli_enqueue(struct obd_export *exp, } if (lvb_len) { void *tmplvb; - tmplvb = lustre_swab_repbuf(req, 1, lvb_len, + tmplvb = lustre_swab_repbuf(req, + DLM_REPLY_REC_OFF, + lvb_len, lvb_swabber); if (tmplvb == NULL) GOTO(cleanup, rc = -EPROTO); @@ -440,7 +444,7 @@ int ldlm_cli_enqueue(struct obd_export *exp, LASSERT(ergo(LIBLUSTRE_CLIENT, type != LDLM_EXTENT || policy->l_extent.end == OBD_OBJECT_EOF)); - reply = lustre_swab_repbuf(req, 0, sizeof(*reply), + reply = lustre_swab_repbuf(req, DLM_LOCKREPLY_OFF, sizeof(*reply), lustre_swab_ldlm_reply); if (reply == NULL) { CERROR("Can't unpack ldlm_reply\n"); @@ -513,7 +517,8 @@ int ldlm_cli_enqueue(struct obd_export *exp, * clobber the LVB with an older one. */ if (lvb_len && (lock->l_req_mode != lock->l_granted_mode)) { void *tmplvb; - tmplvb = lustre_swab_repbuf(req, 1, lvb_len, lvb_swabber); + tmplvb = lustre_swab_repbuf(req, DLM_REPLY_REC_OFF, lvb_len, + lvb_swabber); if (tmplvb == NULL) GOTO(cleanup, rc = -EPROTO); memcpy(lock->l_lvb_data, tmplvb, lvb_len); @@ -587,7 +592,9 @@ int ldlm_cli_convert(struct lustre_handle *lockh, int new_mode, int *flags) struct ldlm_lock *lock; struct ldlm_resource *res; struct ptlrpc_request *req; - int rc, size = sizeof(*body); + int size[2] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREQ_OFF] = sizeof(*body) }; + int rc; ENTRY; lock = ldlm_handle2lock(lockh); @@ -603,24 +610,24 @@ int ldlm_cli_convert(struct lustre_handle *lockh, int new_mode, int *flags) LDLM_DEBUG(lock, "client-side convert"); req = ptlrpc_prep_req(class_exp2cliimp(lock->l_conn_export), - LUSTRE_DLM_VERSION, LDLM_CONVERT, 1, &size, NULL); + LUSTRE_DLM_VERSION, LDLM_CONVERT, 2, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, sizeof(*body)); body->lock_handle1 = lock->l_remote_handle; body->lock_desc.l_req_mode = new_mode; body->lock_flags = *flags; - size = sizeof(*reply); - req->rq_replen = lustre_msg_size(1, &size); + size[DLM_LOCKREPLY_OFF] = sizeof(*reply); + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); if (rc != ELDLM_OK) GOTO(out, rc); - reply = lustre_swab_repbuf(req, 0, sizeof (*reply), + reply = lustre_swab_repbuf(req, DLM_LOCKREPLY_OFF, sizeof(*reply), lustre_swab_ldlm_reply); if (reply == NULL) { CERROR ("Can't unpack ldlm_reply\n"); @@ -656,7 +663,9 @@ int ldlm_cli_cancel(struct lustre_handle *lockh) struct ptlrpc_request *req; struct ldlm_lock *lock; struct ldlm_request *body; - int rc = 0, size = sizeof(*body); + int size[2] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREQ_OFF] = sizeof(*body) }; + int rc = 0; ENTRY; /* concurrent cancels on the same handle can happen */ @@ -691,8 +700,8 @@ int ldlm_cli_cancel(struct lustre_handle *lockh) goto local_cancel; } - req = ptlrpc_prep_req(imp, LUSTRE_DLM_VERSION, LDLM_CANCEL, - 1, &size, NULL); + req = ptlrpc_prep_req(imp, LUSTRE_DLM_VERSION, LDLM_CANCEL, 2, + size, NULL); if (!req) GOTO(out, rc = -ENOMEM); req->rq_no_resend = 1; @@ -701,11 +710,11 @@ int ldlm_cli_cancel(struct lustre_handle *lockh) req->rq_request_portal = LDLM_CANCEL_REQUEST_PORTAL; req->rq_reply_portal = LDLM_CANCEL_REPLY_PORTAL; - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, + sizeof(*body)); body->lock_handle1 = lock->l_remote_handle; - req->rq_replen = lustre_msg_size(0, NULL); - + ptlrpc_req_set_repsize(req, 1, NULL); rc = ptlrpc_queue_wait(req); if (rc == ESTALE) { @@ -1124,7 +1133,7 @@ static int replay_lock_interpret(struct ptlrpc_request *req, lock = req->rq_async_args.pointer_arg[0]; LASSERT(lock != NULL); - reply = lustre_swab_repbuf(req, 0, sizeof (*reply), + reply = lustre_swab_repbuf(req, DLM_LOCKREPLY_OFF, sizeof(*reply), lustre_swab_ldlm_reply); if (reply == NULL) { CERROR("Can't unpack ldlm_reply\n"); @@ -1147,8 +1156,8 @@ static int replay_one_lock(struct obd_import *imp, struct ldlm_lock *lock) struct ptlrpc_request *req; struct ldlm_request *body; struct ldlm_reply *reply; - int buffers = 1; - int size[2]; + int buffers = 2; + int size[3] = { sizeof(struct ptlrpc_body) }; int flags; ENTRY; @@ -1183,26 +1192,26 @@ static int replay_one_lock(struct obd_import *imp, struct ldlm_lock *lock) else flags = LDLM_FL_REPLAY; - size[0] = sizeof(*body); - req = ptlrpc_prep_req(imp, LUSTRE_DLM_VERSION, LDLM_ENQUEUE, - 1, size, NULL); + size[DLM_LOCKREQ_OFF] = sizeof(*body); + req = ptlrpc_prep_req(imp, LUSTRE_DLM_VERSION, LDLM_ENQUEUE, 2, size, + NULL); if (!req) RETURN(-ENOMEM); /* We're part of recovery, so don't wait for it. */ req->rq_send_state = LUSTRE_IMP_REPLAY_LOCKS; - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, sizeof(*body)); ldlm_lock2desc(lock, &body->lock_desc); body->lock_flags = flags; ldlm_lock2handle(lock, &body->lock_handle1); - size[0] = sizeof(*reply); + size[DLM_LOCKREPLY_OFF] = sizeof(*reply); if (lock->l_lvb_len != 0) { - buffers = 2; - size[1] = lock->l_lvb_len; + buffers = 3; + size[DLM_REPLY_REC_OFF] = lock->l_lvb_len; } - req->rq_replen = lustre_msg_size(buffers, size); + ptlrpc_req_set_repsize(req, buffers, size); LDLM_DEBUG(lock, "replaying lock:"); diff --git a/lustre/liblustre/dir.c b/lustre/liblustre/dir.c index 96806aa..53f9c61 100644 --- a/lustre/liblustre/dir.c +++ b/lustre/liblustre/dir.c @@ -106,9 +106,11 @@ static int llu_dir_do_readpage(struct inode *inode, struct page *page) rc = mdc_readpage(sbi->ll_mdc_exp, &mdc_fid, offset, page, &request); if (!rc) { - body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*body)); - LASSERT (body != NULL); /* checked by mdc_readpage() */ - LASSERT_REPSWABBED (request, 0); /* swabbed by mdc_readpage() */ + body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); + LASSERT(body != NULL); /* checked by mdc_readpage() */ + /* swabbed by mdc_readpage() */ + LASSERT_REPSWABBED(request, REPLY_REC_OFF); st->st_size = body->size; } else { diff --git a/lustre/liblustre/file.c b/lustre/liblustre/file.c index 19ce42b..db886b7 100644 --- a/lustre/liblustre/file.c +++ b/lustre/liblustre/file.c @@ -130,9 +130,9 @@ static int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it) struct mds_body *body; ENTRY; - body = lustre_msg_buf (req->rq_repmsg, 1, sizeof (*body)); - LASSERT (body != NULL); /* reply already checked out */ - LASSERT_REPSWABBED (req, 1); /* and swabbed down */ + body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body)); + LASSERT(body != NULL); /* reply already checked out */ + LASSERT_REPSWABBED(req, DLM_REPLY_REC_OFF); /* and swabbed down */ /* already opened? */ if (lli->lli_open_count++) @@ -238,7 +238,7 @@ int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir) ENTRY; /* req is swabbed so this is safe */ - body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body)); + body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, sizeof(*body)); if (!(body->valid & OBD_MD_FLEASIZE)) RETURN(0); @@ -252,7 +252,8 @@ int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir) * to this file. Use this EA to unlink the objects on the OST. * It's opaque so we don't swab here; we leave it to obd_unpackmd() to * check it is complete and sensible. */ - eadata = lustre_swab_repbuf(request, 1, body->eadatasize, NULL); + eadata = lustre_swab_repbuf(request, REPLY_REC_OFF+1, body->eadatasize, + NULL); LASSERT(eadata != NULL); if (eadata == NULL) { CERROR("Can't unpack MDS EA data\n"); @@ -277,7 +278,7 @@ int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir) if (body->valid & OBD_MD_FLCOOKIE) { oa->o_valid |= OBD_MD_FLCOOKIE; oti.oti_logcookies = - lustre_msg_buf(request->rq_repmsg, 2, + lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF + 2, sizeof(struct llog_cookie) * lsm->lsm_stripe_count); if (oti.oti_logcookies == NULL) { diff --git a/lustre/liblustre/namei.c b/lustre/liblustre/namei.c index 8f47209..503480c 100644 --- a/lustre/liblustre/namei.c +++ b/lustre/liblustre/namei.c @@ -279,7 +279,7 @@ static int llu_pb_revalidate(struct pnode *pnode, int flags, if (rc < 0) GOTO(out, rc = 0); - rc = pnode_revalidate_finish(req, 1, it, pnode); + rc = pnode_revalidate_finish(req, DLM_REPLY_REC_OFF, it, pnode); if (rc != 0) { ll_intent_release(it); GOTO(out, rc = 0); @@ -444,7 +444,7 @@ static int llu_lookup_it(struct inode *parent, struct pnode *pnode, if (rc < 0) GOTO(out, rc); - rc = lookup_it_finish(req, 1, it, &icbd); + rc = lookup_it_finish(req, DLM_REPLY_REC_OFF, it, &icbd); if (rc != 0) { ll_intent_release(it); GOTO(out, rc); diff --git a/lustre/liblustre/rw.c b/lustre/liblustre/rw.c index 244271b..8917eff 100644 --- a/lustre/liblustre/rw.c +++ b/lustre/liblustre/rw.c @@ -179,7 +179,8 @@ static int llu_glimpse_callback(struct ldlm_lock *lock, void *reqp) struct inode *inode = llu_inode_from_lock(lock); struct llu_inode_info *lli; struct ost_lvb *lvb; - int rc, size = sizeof(*lvb), stripe = 0; + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*lvb) }; + int rc, stripe = 0; ENTRY; if (inode == NULL) @@ -194,13 +195,13 @@ static int llu_glimpse_callback(struct ldlm_lock *lock, void *reqp) if (lli->lli_smd->lsm_stripe_count > 1) stripe = llu_lock_to_stripe_offset(inode, lock); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) { CERROR("lustre_pack_reply: %d\n", rc); GOTO(iput, rc); } - lvb = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*lvb)); + lvb = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*lvb)); lvb->lvb_size = lli->lli_smd->lsm_oinfo[stripe].loi_kms; LDLM_DEBUG(lock, "i_size: %llu -> stripe number %u -> kms "LPU64, @@ -211,7 +212,7 @@ static int llu_glimpse_callback(struct ldlm_lock *lock, void *reqp) /* These errors are normal races, so we don't want to fill the console * with messages by calling ptlrpc_error() */ if (rc == -ELDLM_NO_LOCK_DATA) - lustre_pack_reply(req, 0, NULL, NULL); + lustre_pack_reply(req, 1, NULL, NULL); req->rq_status = rc; return rc; diff --git a/lustre/liblustre/super.c b/lustre/liblustre/super.c index 7517ef1..4ee0dc9 100644 --- a/lustre/liblustre/super.c +++ b/lustre/liblustre/super.c @@ -452,7 +452,7 @@ static int llu_inode_revalidate(struct inode *inode) (long long)llu_i2stat(inode)->st_ino); RETURN(-abs(rc)); } - rc = mdc_req2lustre_md(req, 0, sbi->ll_osc_exp, &md); + rc = mdc_req2lustre_md(req, REPLY_REC_OFF, sbi->ll_osc_exp,&md); /* XXX Too paranoid? */ if (((md.body->valid ^ valid) & OBD_MD_FLEASIZE) && @@ -688,7 +688,8 @@ int llu_setattr_raw(struct inode *inode, struct iattr *attr) RETURN(rc); } - rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md); + rc = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, + &md); if (rc) { ptlrpc_req_finished(request); RETURN(rc); @@ -903,9 +904,10 @@ static int llu_readlink_internal(struct inode *inode, RETURN(rc); } - body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body)); - LASSERT (body != NULL); - LASSERT_REPSWABBED (*request, 0); + body = lustre_msg_buf((*request)->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); + LASSERT(body != NULL); + LASSERT_REPSWABBED(*request, REPLY_REC_OFF); if ((body->valid & OBD_MD_LINKNAME) == 0) { CERROR ("OBD_MD_LINKNAME not set on reply\n"); @@ -919,7 +921,8 @@ static int llu_readlink_internal(struct inode *inode, GOTO(failed, rc = -EPROTO); } - *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen); + *symname = lustre_msg_buf((*request)->rq_repmsg, REPLY_REC_OFF + 1, + symlen); if (*symname == NULL || strnlen(*symname, symlen) != symlen - 1) { /* not full/NULL terminated */ @@ -1828,7 +1831,7 @@ llu_fsswop_mount(const char *source, GOTO(out_osc, err); } - err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md); + err = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md); if (err) { CERROR("failed to understand root inode md: rc = %d\n",err); GOTO(out_request, err); diff --git a/lustre/llite/dcache.c b/lustre/llite/dcache.c index 71336cc..4f0ec58 100644 --- a/lustre/llite/dcache.c +++ b/lustre/llite/dcache.c @@ -232,7 +232,7 @@ int revalidate_it_finish(struct ptlrpc_request *request, int offset, RETURN(-ENOENT); rc = ll_prep_inode(ll_i2sbi(de->d_inode)->ll_osc_exp, &de->d_inode, - request, offset,NULL); + request, offset, NULL); RETURN(rc); } @@ -327,7 +327,7 @@ int ll_revalidate_it(struct dentry *de, int lookup_flags, GOTO(out, rc = 0); } - rc = revalidate_it_finish(req, 1, it, de); + rc = revalidate_it_finish(req, DLM_REPLY_REC_OFF, it, de); if (rc != 0) { ll_intent_release(it); GOTO(out, rc = 0); diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 2d4a78e..d2c2a4f 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -74,9 +74,11 @@ static int ll_dir_readpage(struct file *file, struct page *page) rc = mdc_readpage(ll_i2sbi(inode)->ll_mdc_exp, &mdc_fid, offset, page, &request); if (!rc) { - body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*body)); - LASSERT (body != NULL); /* checked by mdc_readpage() */ - LASSERT_REPSWABBED (request, 0); /* swabbed by mdc_readpage() */ + body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); + LASSERT(body != NULL); /* checked by mdc_readpage() */ + /* swabbed by mdc_readpage() */ + LASSERT_REPSWABBED(request, REPLY_REC_OFF); inode->i_size = body->size; SetPageUptodate(page); @@ -501,17 +503,20 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, RETURN(rc); } - body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body)); - LASSERT(body != NULL); /* checked by mdc_getattr_name */ - LASSERT_REPSWABBED(request, 0);/* swabbed by mdc_getattr_name */ + body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); + LASSERT(body != NULL); /* checked by mdc_getattr_name */ + /* swabbed by mdc_getattr_name */ + LASSERT_REPSWABBED(request, REPLY_REC_OFF); lmmsize = body->eadatasize; if (lmmsize == 0) GOTO(out_get, rc = -ENODATA); - lmm = lustre_msg_buf(request->rq_repmsg, 1, lmmsize); + lmm = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF + 1, + lmmsize); LASSERT(lmm != NULL); - LASSERT_REPSWABBED(request, 1); + LASSERT_REPSWABBED(request, REPLY_REC_OFF + 1); /* * This is coming from the MDS, so is probably in @@ -563,9 +568,11 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, GOTO(out_name, rc); } - body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*body)); - LASSERT(body != NULL); /* checked by mdc_getattr_name */ - LASSERT_REPSWABBED(request, 0);/* swabbed by mdc_getattr_name */ + body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); + LASSERT(body != NULL); /* checked by mdc_getattr_name */ + /* swabbed by mdc_getattr_name */ + LASSERT_REPSWABBED(request, REPLY_REC_OFF); lmmsize = body->eadatasize; @@ -575,9 +582,10 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, if (lmmsize > 4096) GOTO(out_req, rc = -EFBIG); - lmm = lustre_msg_buf(request->rq_repmsg, 1, lmmsize); + lmm = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF + 1, + lmmsize); LASSERT(lmm != NULL); - LASSERT_REPSWABBED(request, 1); + LASSERT_REPSWABBED(request, REPLY_REC_OFF + 1); /* * This is coming from the MDS, so is probably in @@ -690,8 +698,9 @@ out_free_memmd: struct ptlrpc_request *req = NULL; char *buf = NULL; int rc, len = 0; - char *bufs[2], *str; - int lens[2], size; + char *bufs[3] = { NULL }, *str; + int lens[3] = { sizeof(struct ptlrpc_body) }; + int size[2] = { sizeof(struct ptlrpc_body) }; rc = obd_ioctl_getdata(&buf, &len, (void *)arg); if (rc) @@ -703,28 +712,30 @@ out_free_memmd: RETURN(-EINVAL); } - lens[0] = data->ioc_inllen1; - bufs[0] = data->ioc_inlbuf1; + lens[REQ_REC_OFF] = data->ioc_inllen1; + bufs[REQ_REC_OFF] = data->ioc_inlbuf1; if (data->ioc_inllen2) { - lens[1] = data->ioc_inllen2; - bufs[1] = data->ioc_inlbuf2; + lens[REQ_REC_OFF + 1] = data->ioc_inllen2; + bufs[REQ_REC_OFF + 1] = data->ioc_inlbuf2; } else { - lens[1] = 0; - bufs[1] = NULL; + lens[REQ_REC_OFF + 1] = 0; + bufs[REQ_REC_OFF + 1] = NULL; } - size = data->ioc_plen1; + req = ptlrpc_prep_req(sbi2mdc(sbi)->cl_import, - LUSTRE_LOG_VERSION, LLOG_CATINFO, - 2, lens, bufs); + LUSTRE_LOG_VERSION, LLOG_CATINFO, 3, lens, + bufs); if (!req) GOTO(out_catinfo, rc = -ENOMEM); - req->rq_replen = lustre_msg_size(1, &size); + + size[REPLY_REC_OFF] = data->ioc_plen1; + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); - str = lustre_msg_string(req->rq_repmsg, 0, data->ioc_plen1); + str = lustre_msg_string(req->rq_repmsg, REPLY_REC_OFF, + data->ioc_plen1); if (!rc) - rc = copy_to_user(data->ioc_pbuf1, str, - data->ioc_plen1); + rc = copy_to_user(data->ioc_pbuf1, str,data->ioc_plen1); ptlrpc_req_finished(req); out_catinfo: obd_ioctl_freedata(buf, len); diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 29dcb3b..31b2fde 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -179,8 +179,8 @@ static int ll_intent_file_open(struct file *file, void *lmm, } rc = ll_prep_inode(sbi->ll_osc_exp, &file->f_dentry->d_inode, - (struct ptlrpc_request *)itp->d.lustre.it_data, 1, - NULL); + (struct ptlrpc_request *)itp->d.lustre.it_data, + DLM_REPLY_REC_OFF, NULL); out: RETURN(rc); } @@ -193,9 +193,9 @@ static void ll_och_fill(struct ll_inode_info *lli, struct lookup_intent *it, LASSERT(och); - body = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body)); + body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body)); LASSERT(body != NULL); /* reply already checked out */ - LASSERT_REPSWABBED(req, 1); /* and swabbed in mdc_enqueue */ + LASSERT_REPSWABBED(req, DLM_REPLY_REC_OFF); /* and swabbed in mdc_enqueue */ memcpy(&och->och_fh, &body->handle, sizeof(body->handle)); och->och_magic = OBD_CLIENT_HANDLE_MAGIC; @@ -673,7 +673,8 @@ static int ll_glimpse_callback(struct ldlm_lock *lock, void *reqp) struct ll_inode_info *lli; struct lov_stripe_md *lsm; struct ost_lvb *lvb; - int rc, size = sizeof(*lvb), stripe; + int rc, stripe; + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*lvb) }; ENTRY; if (inode == NULL) @@ -690,13 +691,13 @@ static int ll_glimpse_callback(struct ldlm_lock *lock, void *reqp) if (stripe < 0) GOTO(iput, rc = -ELDLM_NO_LOCK_DATA); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) { CERROR("lustre_pack_reply: %d\n", rc); GOTO(iput, rc); } - lvb = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*lvb)); + lvb = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*lvb)); lvb->lvb_size = lli->lli_smd->lsm_oinfo[stripe].loi_kms; lvb->lvb_mtime = LTIME_S(inode->i_mtime); lvb->lvb_atime = LTIME_S(inode->i_atime); @@ -706,7 +707,6 @@ static int ll_glimpse_callback(struct ldlm_lock *lock, void *reqp) " atime "LPU64", mtime "LPU64", ctime "LPU64, inode->i_size, stripe, lvb->lvb_size, lvb->lvb_mtime, lvb->lvb_atime, lvb->lvb_ctime); - GOTO(iput, 0); iput: iput(inode); @@ -714,7 +714,7 @@ static int ll_glimpse_callback(struct ldlm_lock *lock, void *reqp) /* These errors are normal races, so we don't want to fill the console * with messages by calling ptlrpc_error() */ if (rc == -ELDLM_NO_LOCK_DATA) - lustre_pack_reply(req, 0, NULL, NULL); + lustre_pack_reply(req, 1, NULL, NULL); req->rq_status = rc; return rc; @@ -1241,7 +1241,7 @@ static int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file, if (rc < 0) GOTO(out, rc); - rc = mdc_req2lustre_md(req, 1, exp, &md); + rc = mdc_req2lustre_md(req, DLM_REPLY_REC_OFF, exp, &md); if (rc) GOTO(out, rc); ll_update_inode(f->f_dentry->d_inode, &md); @@ -1970,7 +1970,7 @@ int ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it) GOTO (out, rc); } - rc = revalidate_it_finish(req, 1, &oit, dentry); + rc = revalidate_it_finish(req, DLM_REPLY_REC_OFF, &oit, dentry); if (rc != 0) { ll_intent_release(&oit); GOTO(out, rc); @@ -1995,8 +1995,9 @@ int ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it) rc = ll_inode_revalidate_fini(inode, rc); RETURN(rc); } - - rc = ll_prep_inode(sbi->ll_osc_exp, &inode, req, 0, NULL); + + rc = ll_prep_inode(sbi->ll_osc_exp, &inode, req, REPLY_REC_OFF, + NULL); if (rc) GOTO(out, rc); } diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index ab45d10..488066f 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -288,7 +288,7 @@ int client_common_fill_super(struct super_block *sb, char *mdc, char *osc) GOTO(out_osc, err); } - err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md); + err = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md); if (err) { CERROR("failed to understand root inode md: rc = %d\n",err); ptlrpc_req_finished (request); @@ -1170,7 +1170,8 @@ int ll_setattr_raw(struct inode *inode, struct iattr *attr) RETURN(rc); } - rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md); + rc = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, + &md); if (rc) { ptlrpc_req_finished(request); RETURN(rc); @@ -1607,7 +1608,8 @@ int ll_iocontrol(struct inode *inode, struct file *file, RETURN(-abs(rc)); } - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); if (body->flags & S_APPEND) flags |= EXT3_APPEND_FL; @@ -1616,7 +1618,7 @@ int ll_iocontrol(struct inode *inode, struct file *file, if (body->flags & S_NOATIME) flags |= EXT3_NOATIME_FL; - ptlrpc_req_finished (req); + ptlrpc_req_finished(req); RETURN(put_user(flags, (int *)arg)); } diff --git a/lustre/llite/llite_nfs.c b/lustre/llite/llite_nfs.c index 5fb7eef..123fef6 100644 --- a/lustre/llite/llite_nfs.c +++ b/lustre/llite/llite_nfs.c @@ -84,7 +84,7 @@ static struct inode * search_inode_for_lustre(struct super_block *sb, return ERR_PTR(rc); } - rc = ll_prep_inode(sbi->ll_osc_exp, &inode, req, 0, sb); + rc = ll_prep_inode(sbi->ll_osc_exp, &inode, req, REPLY_REC_OFF, sb); if (rc) { ptlrpc_req_finished(req); return ERR_PTR(rc); @@ -238,7 +238,7 @@ struct dentry *ll_get_parent(struct dentry *dchild) CERROR("failure %d inode %lu get parent\n", rc, dir->i_ino); return ERR_PTR(rc); } - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (*body)); LASSERT((body->valid & OBD_MD_FLGENER) && (body->valid & OBD_MD_FLID)); diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 29dc6c8..0cf1eef 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -455,7 +455,7 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, if (rc < 0) GOTO(out, retval = ERR_PTR(rc)); - rc = lookup_it_finish(req, 1, it, &icbd); + rc = lookup_it_finish(req, DLM_REPLY_REC_OFF, it, &icbd); if (rc != 0) { ll_intent_release(it); GOTO(out, retval = ERR_PTR(rc)); @@ -511,7 +511,8 @@ static struct inode *ll_create_node(struct inode *dir, const char *name, LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF)); request = it->d.lustre.it_data; it_clear_disposition(it, DISP_ENQ_CREATE_REF); - rc = ll_prep_inode(sbi->ll_osc_exp, &inode, request, 1, dir->i_sb); + rc = ll_prep_inode(sbi->ll_osc_exp, &inode, request, DLM_REPLY_REC_OFF, + dir->i_sb); if (rc) GOTO(out, inode = ERR_PTR(rc)); @@ -559,7 +560,8 @@ static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode, if (rc) RETURN(rc); - mdc_store_inode_generation(request, MDS_REQ_INTENT_REC_OFF, 1); + mdc_store_inode_generation(request, DLM_INTENT_REC_OFF, + DLM_REPLY_REC_OFF); inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len, NULL, 0, mode, 0, it); if (IS_ERR(inode)) { @@ -619,11 +621,11 @@ static int ll_mknod_generic(struct inode *dir, struct qstr *name, int mode, current->cap_effective, rdev, &request); if (err) break; - ll_update_times(request, 0, dir); + ll_update_times(request, REPLY_REC_OFF, dir); if (dchild) { - err = ll_prep_inode(sbi->ll_osc_exp, &inode, request, 0, - dchild->d_sb); + err = ll_prep_inode(sbi->ll_osc_exp, &inode, request, + REPLY_REC_OFF, dchild->d_sb); if (err) break; @@ -644,10 +646,9 @@ static int ll_mknod_generic(struct inode *dir, struct qstr *name, int mode, static int ll_create_nd(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd) { - if (!nd || !nd->intent.d.lustre.it_disposition) { + if (!nd || !nd->intent.d.lustre.it_disposition) /* No saved request? Just mknod the file */ return ll_mknod_generic(dir, &dentry->d_name, mode, 0, dentry); - } return ll_create_it(dir, dentry, mode, &nd->intent); } @@ -673,7 +674,7 @@ static int ll_symlink_generic(struct inode *dir, struct qstr *name, current->fsuid, current->fsgid, current->cap_effective, 0, &request); if (err == 0) - ll_update_times(request, 0, dir); + ll_update_times(request, REPLY_REC_OFF, dir); ptlrpc_req_finished(request); RETURN(err); @@ -697,7 +698,7 @@ static int ll_link_generic(struct inode *src, struct inode *dir, name->len, 0); err = mdc_link(sbi->ll_mdc_exp, &op_data, &request); if (err == 0) - ll_update_times(request, 0, dir); + ll_update_times(request, REPLY_REC_OFF, dir); ptlrpc_req_finished(request); @@ -726,10 +727,10 @@ static int ll_mkdir_generic(struct inode *dir, struct qstr *name, int mode, if (err) GOTO(out, err); - ll_update_times(request, 0, dir); + ll_update_times(request, REPLY_REC_OFF, dir); if (dchild) { - err = ll_prep_inode(sbi->ll_osc_exp, &inode, request, 0, - dchild->d_sb); + err = ll_prep_inode(sbi->ll_osc_exp, &inode, request, + REPLY_REC_OFF, dchild->d_sb); if (err) GOTO(out, err); d_instantiate(dchild, inode); @@ -767,7 +768,7 @@ static int ll_rmdir_generic(struct inode *dir, struct dentry *dparent, name->len, S_IFDIR); rc = mdc_unlink(ll_i2sbi(dir)->ll_mdc_exp, &op_data, &request); if (rc == 0) - ll_update_times(request, 0, dir); + ll_update_times(request, REPLY_REC_OFF, dir); ptlrpc_req_finished(request); RETURN(rc); } @@ -783,7 +784,7 @@ int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir) ENTRY; /* req is swabbed so this is safe */ - body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body)); + body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, sizeof(*body)); if (!(body->valid & OBD_MD_FLEASIZE)) RETURN(0); @@ -797,7 +798,8 @@ int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir) * to this file. Use this EA to unlink the objects on the OST. * It's opaque so we don't swab here; we leave it to obd_unpackmd() to * check it is complete and sensible. */ - eadata = lustre_swab_repbuf(request, 1, body->eadatasize, NULL); + eadata = lustre_swab_repbuf(request, REPLY_REC_OFF + 1, + body->eadatasize, NULL); LASSERT(eadata != NULL); if (eadata == NULL) { CERROR("Can't unpack MDS EA data\n"); @@ -826,7 +828,7 @@ int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir) if (body->valid & OBD_MD_FLCOOKIE) { oa->o_valid |= OBD_MD_FLCOOKIE; oti.oti_logcookies = - lustre_msg_buf(request->rq_repmsg, 2, + lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF + 2, sizeof(struct llog_cookie) * lsm->lsm_stripe_count); if (oti.oti_logcookies == NULL) { @@ -861,7 +863,7 @@ static int ll_unlink_generic(struct inode * dir, struct qstr *name) if (rc) GOTO(out, rc); - ll_update_times(request, 0, dir); + ll_update_times(request, REPLY_REC_OFF, dir); rc = ll_objects_destroy(request, dir); out: @@ -887,8 +889,8 @@ static int ll_rename_generic(struct inode *src, struct qstr *src_name, src_name->name, src_name->len, tgt_name->name, tgt_name->len, &request); if (!err) { - ll_update_times(request, 0, src); - ll_update_times(request, 0, tgt); + ll_update_times(request, REPLY_REC_OFF, src); + ll_update_times(request, REPLY_REC_OFF, tgt); err = ll_objects_destroy(request, src); } diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c index b6e7d51..c83c6b2 100644 --- a/lustre/llite/super25.c +++ b/lustre/llite/super25.c @@ -136,6 +136,7 @@ static void __exit exit_lustre_lite(void) ll_unregister_cache(&ll_cache_definition); ll_destroy_inodecache(); + rc = kmem_cache_destroy(ll_file_data_slab); LASSERTF(rc == 0, "couldn't destroy ll_file_data slab\n"); if (ll_async_page_slab) { diff --git a/lustre/llite/symlink.c b/lustre/llite/symlink.c index c663371..3e5150e 100644 --- a/lustre/llite/symlink.c +++ b/lustre/llite/symlink.c @@ -56,29 +56,31 @@ static int ll_readlink_internal(struct inode *inode, GOTO (failed, rc); } - body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body)); - LASSERT (body != NULL); - LASSERT_REPSWABBED (*request, 0); + body = lustre_msg_buf((*request)->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); + LASSERT(body != NULL); + LASSERT_REPSWABBED(*request, REPLY_REC_OFF); if ((body->valid & OBD_MD_LINKNAME) == 0) { - CERROR ("OBD_MD_LINKNAME not set on reply\n"); - GOTO (failed, rc = -EPROTO); + CERROR("OBD_MD_LINKNAME not set on reply\n"); + GOTO(failed, rc = -EPROTO); } - LASSERT (symlen != 0); + LASSERT(symlen != 0); if (body->eadatasize != symlen) { - CERROR ("inode %lu: symlink length %d not expected %d\n", + CERROR("inode %lu: symlink length %d not expected %d\n", inode->i_ino, body->eadatasize - 1, symlen - 1); - GOTO (failed, rc = -EPROTO); + GOTO(failed, rc = -EPROTO); } - *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen); + *symname = lustre_msg_buf((*request)->rq_repmsg, REPLY_REC_OFF + 1, + symlen); if (*symname == NULL || strnlen (*symname, symlen) != symlen - 1) { /* not full/NULL terminated */ - CERROR ("inode %lu: symlink not NULL terminated string" + CERROR("inode %lu: symlink not NULL terminated string" "of length %d\n", inode->i_ino, symlen - 1); - GOTO (failed, rc = -EPROTO); + GOTO(failed, rc = -EPROTO); } OBD_ALLOC(lli->lli_symlink_name, symlen); diff --git a/lustre/llite/xattr.c b/lustre/llite/xattr.c index 3252af8..3cc486b 100644 --- a/lustre/llite/xattr.c +++ b/lustre/llite/xattr.c @@ -210,8 +210,8 @@ int ll_getxattr_common(struct inode *inode, const char *name, do_getxattr: ll_inode2fid(&fid, inode); - rc = mdc_getxattr(sbi->ll_mdc_exp, &fid, valid, name, NULL, 0, - size, &req); + rc = mdc_getxattr(sbi->ll_mdc_exp, &fid, valid, name, NULL, 0, size, + &req); if (rc) { if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) { LCONSOLE_INFO("Disabling user_xattr feature because " @@ -221,9 +221,9 @@ do_getxattr: RETURN(rc); } - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body)); LASSERT(body); - LASSERT_REPSWABBED(req, 0); + LASSERT_REPSWABBED(req, REPLY_REC_OFF); /* only detect the xattr size */ if (size == 0) @@ -235,17 +235,19 @@ do_getxattr: GOTO(out, rc = -ERANGE); } - if (req->rq_repmsg->bufcount < 2) { - CERROR("reply bufcount %u\n", req->rq_repmsg->bufcount); + if (lustre_msg_bufcount(req->rq_repmsg) < 3) { + CERROR("reply bufcount %u\n", + lustre_msg_bufcount(req->rq_repmsg)); GOTO(out, rc = -EFAULT); } /* do not need swab xattr data */ - LASSERT_REPSWAB(req, 1); - xdata = lustre_msg_buf(req->rq_repmsg, 1, body->eadatasize); + LASSERT_REPSWAB(req, REPLY_REC_OFF + 1); + xdata = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, + body->eadatasize); if (!xdata) { CERROR("can't extract: %u : %u\n", body->eadatasize, - lustre_msg_buflen(req->rq_repmsg, 1)); + lustre_msg_buflen(req->rq_repmsg, REPLY_REC_OFF + 1)); GOTO(out, rc = -EFAULT); } diff --git a/lustre/mdc/mdc_internal.h b/lustre/mdc/mdc_internal.h index 2ae5a1b..09351eb 100644 --- a/lustre/mdc/mdc_internal.h +++ b/lustre/mdc/mdc_internal.h @@ -10,9 +10,9 @@ void mdc_pack_req_body(struct ptlrpc_request *req, int offset, __u64 valid, struct ll_fid *fid, int ea_size); void mdc_pack_rep_body(struct ptlrpc_request *); -void mdc_readdir_pack(struct ptlrpc_request *req, int pos, __u64 offset, - __u32 size, struct ll_fid *mdc_fid); -void mdc_getattr_pack(struct ptlrpc_request *req, int valid, int offset, +void mdc_readdir_pack(struct ptlrpc_request *req, int offset, __u64 pg_off, + __u32 size, struct ll_fid *mdc_fid); +void mdc_getattr_pack(struct ptlrpc_request *req, int offset, int valid, int flags, struct mdc_op_data *data); void mdc_setattr_pack(struct ptlrpc_request *req, int offset, struct mdc_op_data *data, diff --git a/lustre/mdc/mdc_lib.c b/lustre/mdc/mdc_lib.c index 9355db2..563085b 100644 --- a/lustre/mdc/mdc_lib.c +++ b/lustre/mdc/mdc_lib.c @@ -38,17 +38,17 @@ #endif #endif -void mdc_readdir_pack(struct ptlrpc_request *req, int pos, __u64 offset, - __u32 size, struct ll_fid *mdc_fid) +void mdc_readdir_pack(struct ptlrpc_request *req, int offset, __u64 pg_off, + __u32 size, struct ll_fid *fid) { struct mds_body *b; - b = lustre_msg_buf(req->rq_reqmsg, pos, sizeof (*b)); + b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*b)); b->fsuid = current->fsuid; b->fsgid = current->fsgid; b->capability = current->cap_effective; - b->fid1 = *mdc_fid; - b->size = offset; /* !! */ + b->fid1 = *fid; + b->size = pg_off; /* !! */ b->suppgid = -1; b->nlink = size; /* !! */ } @@ -170,11 +170,11 @@ void mdc_open_pack(struct ptlrpc_request *req, int offset, } void mdc_setattr_pack(struct ptlrpc_request *req, int offset, - struct mdc_op_data *data, struct iattr *iattr, - void *ea, int ealen, void *ea2, int ea2len) + struct mdc_op_data *data, struct iattr *iattr, void *ea, + int ealen, void *ea2, int ea2len) { struct mds_rec_setattr *rec = lustre_msg_buf(req->rq_reqmsg, offset, - sizeof (*rec)); + sizeof(*rec)); rec->sa_opcode = REINT_SETATTR; rec->sa_fsuid = current->fsuid; rec->sa_fsgid = current->fsgid; @@ -290,7 +290,7 @@ void mdc_getattr_pack(struct ptlrpc_request *req, int offset, int valid, int flags, struct mdc_op_data *data) { struct mds_body *b; - b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*b)); + b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*b)); b->fsuid = current->fsuid; b->fsgid = current->fsgid; @@ -314,7 +314,7 @@ void mdc_close_pack(struct ptlrpc_request *req, int offset, struct obdo *oa, { struct mds_body *body; - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body)); mdc_pack_fid(&body->fid1, oa->o_id, 0, oa->o_mode); memcpy(&body->handle, &och->och_fh, sizeof(body->handle)); diff --git a/lustre/mdc/mdc_locks.c b/lustre/mdc/mdc_locks.c index c67cff3..6dbf7f5 100644 --- a/lustre/mdc/mdc_locks.c +++ b/lustre/mdc/mdc_locks.c @@ -197,16 +197,16 @@ static int round_up(int val) * but this is incredibly unlikely, and questionable whether the client * could do MDS recovery under OOM anyways... */ static void mdc_realloc_openmsg(struct ptlrpc_request *req, - struct mds_body *body, int size[5]) + struct mds_body *body, int size[6]) { int new_size, old_size; struct lustre_msg *new_msg; /* save old size */ - old_size = lustre_msg_size(5, size); + old_size = lustre_msg_size(lustre_request_magic(req), 6, size); - size[4] = body->eadatasize; - new_size = lustre_msg_size(5, size); + size[DLM_INTENT_REC_OFF + 2] = body->eadatasize; + new_size = lustre_msg_size(lustre_request_magic(req), 6, size); OBD_ALLOC(new_msg, new_size); if (new_msg != NULL) { struct lustre_msg *old_msg = req->rq_reqmsg; @@ -215,7 +215,8 @@ static void mdc_realloc_openmsg(struct ptlrpc_request *req, DEBUG_REQ(D_INFO, req, "replace reqmsg for larger EA %u\n", body->eadatasize); memcpy(new_msg, old_msg, old_size); - new_msg->buflens[4] = body->eadatasize; + lustre_msg_set_buflen(new_msg, DLM_INTENT_REC_OFF + 2, + body->eadatasize); spin_lock_irqsave(&req->rq_lock, irqflags); req->rq_reqmsg = new_msg; @@ -250,16 +251,19 @@ int mdc_enqueue(struct obd_export *exp, ldlm_policy_data_t policy = { .l_inodebits = { MDS_INODELOCK_LOOKUP } }; struct ldlm_request *lockreq; struct ldlm_intent *lit; - int size[6] = {[MDS_REQ_INTENT_LOCKREQ_OFF] = sizeof(*lockreq), - [MDS_REQ_INTENT_IT_OFF] = sizeof(*lit) }; - struct ldlm_reply *dlm_rep; - int repsize[4] = {sizeof(*dlm_rep), - sizeof(struct mds_body), - obddev->u.cli.cl_max_mds_easize}; + struct ldlm_reply *lockrep; + int size[7] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREQ_OFF] = sizeof(*lockreq), + [DLM_INTENT_IT_OFF] = sizeof(*lit) }; + int repsize[5] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREPLY_OFF] = sizeof(*lockrep), + [DLM_REPLY_REC_OFF] = sizeof(struct mds_body), + [DLM_REPLY_REC_OFF+1] = obddev->u.cli. + cl_max_mds_easize }; + int flags = extra_lock_flags | LDLM_FL_HAS_INTENT; + int repbufcnt = 4, rc; void *eadata; unsigned long irqflags; - int repbufcnt = 3, req_buffers = 2; - int rc, flags = extra_lock_flags | LDLM_FL_HAS_INTENT; ENTRY; LASSERTF(lock_type == LDLM_IBITS, "lock type %d\n", lock_type); @@ -269,21 +273,22 @@ int mdc_enqueue(struct obd_export *exp, if (it->it_op & IT_OPEN) { it->it_create_mode |= S_IFREG; - size[req_buffers++] = sizeof(struct mds_rec_create); - size[req_buffers++] = data->namelen + 1; + size[DLM_INTENT_REC_OFF] = sizeof(struct mds_rec_create); + size[DLM_INTENT_REC_OFF + 1] = data->namelen + 1; /* As an optimization, we allocate an RPC request buffer for * at least a default-sized LOV EA even if we aren't sending * one. We grow the whole request to the next power-of-two * size since we get that much from a slab allocation anyways. * This avoids an allocation below in the common case where * we need to save a default-sized LOV EA for open replay. */ - size[req_buffers++] = max(lmmsize, + size[DLM_INTENT_REC_OFF + 2] = max(lmmsize, obddev->u.cli.cl_default_mds_easize); - rc = lustre_msg_size(req_buffers, size); + rc = lustre_msg_size(class_exp2cliimp(exp)->imp_msg_magic, 6, + size); if (rc & (rc - 1)) - size[req_buffers - 1] = min(size[req_buffers - 1] + - round_up(rc) - rc, - obddev->u.cli.cl_max_mds_easize); + size[DLM_INTENT_REC_OFF + 2] = + min(size[DLM_INTENT_REC_OFF+2]+round_up(rc)-rc, + obddev->u.cli.cl_max_mds_easize); if (it->it_flags & O_JOIN_FILE) { __u64 head_size = *(__u32*)cb_data; @@ -291,20 +296,23 @@ int mdc_enqueue(struct obd_export *exp, /* join is like an unlink of the tail */ policy.l_inodebits.bits = MDS_INODELOCK_UPDATE; - size[req_buffers++] = sizeof(struct mds_rec_join); + size[DLM_INTENT_REC_OFF + 3] = + sizeof(struct mds_rec_join); req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION, LDLM_ENQUEUE, - req_buffers, size, NULL); + 7, size, NULL); /* when joining file, cb_data and lmm args together * indicate the head file size*/ - mdc_join_pack(req, req_buffers - 1, data, + mdc_join_pack(req, DLM_INTENT_REC_OFF + 3, data, (head_size << 32) | tsize); cb_data = NULL; lmm = NULL; - } else + } else { req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION, LDLM_ENQUEUE, - req_buffers, size, NULL); + 6, size, NULL); + } + if (!req) RETURN(-ENOMEM); @@ -313,75 +321,73 @@ int mdc_enqueue(struct obd_export *exp, spin_unlock_irqrestore (&req->rq_lock, irqflags); /* pack the intent */ - lit = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_INTENT_IT_OFF, - sizeof (*lit)); + lit = lustre_msg_buf(req->rq_reqmsg, DLM_INTENT_IT_OFF, + sizeof(*lit)); lit->opc = (__u64)it->it_op; /* pack the intended request */ - mdc_open_pack(req, MDS_REQ_INTENT_REC_OFF, data, - it->it_create_mode, 0, - it->it_flags, lmm, lmmsize); + mdc_open_pack(req, DLM_INTENT_REC_OFF, data, it->it_create_mode, + 0, it->it_flags, lmm, lmmsize); repsize[repbufcnt++] = LUSTRE_POSIX_ACL_MAX_SIZE; } else if (it->it_op & IT_UNLINK) { - size[req_buffers++] = sizeof(struct mds_rec_unlink); - size[req_buffers++] = data->namelen + 1; + size[DLM_INTENT_REC_OFF] = sizeof(struct mds_rec_unlink); + size[DLM_INTENT_REC_OFF + 1] = data->namelen + 1; policy.l_inodebits.bits = MDS_INODELOCK_UPDATE; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION, - LDLM_ENQUEUE, req_buffers, size, NULL); + LDLM_ENQUEUE, 5, size, NULL); if (!req) RETURN(-ENOMEM); /* pack the intent */ - lit = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_INTENT_IT_OFF, - sizeof (*lit)); + lit = lustre_msg_buf(req->rq_reqmsg, DLM_INTENT_IT_OFF, + sizeof(*lit)); lit->opc = (__u64)it->it_op; /* pack the intended request */ - mdc_unlink_pack(req, MDS_REQ_INTENT_REC_OFF, data); - /* get ready for the reply */ + mdc_unlink_pack(req, DLM_INTENT_REC_OFF, data); + repsize[repbufcnt++] = obddev->u.cli.cl_max_mds_cookiesize; } else if (it->it_op & (IT_GETATTR | IT_LOOKUP)) { obd_valid valid = OBD_MD_FLGETATTR | OBD_MD_FLEASIZE | OBD_MD_FLACL | OBD_MD_FLMODEASIZE | OBD_MD_FLDIREA; - size[req_buffers++] = sizeof(struct mds_body); - size[req_buffers++] = data->namelen + 1; + size[DLM_INTENT_REC_OFF] = sizeof(struct mds_body); + size[DLM_INTENT_REC_OFF + 1] = data->namelen + 1; if (it->it_op & IT_GETATTR) policy.l_inodebits.bits = MDS_INODELOCK_UPDATE; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION, - LDLM_ENQUEUE, req_buffers, size, NULL); + LDLM_ENQUEUE, 5, size, NULL); if (!req) RETURN(-ENOMEM); /* pack the intent */ - lit = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_INTENT_IT_OFF, - sizeof (*lit)); + lit = lustre_msg_buf(req->rq_reqmsg, DLM_INTENT_IT_OFF, + sizeof(*lit)); lit->opc = (__u64)it->it_op; /* pack the intended request */ - mdc_getattr_pack(req, MDS_REQ_INTENT_REC_OFF, valid, + mdc_getattr_pack(req, DLM_INTENT_REC_OFF, valid, it->it_flags, data); - /* get ready for the reply */ + repsize[repbufcnt++] = LUSTRE_POSIX_ACL_MAX_SIZE; } else if (it->it_op == IT_READDIR) { policy.l_inodebits.bits = MDS_INODELOCK_UPDATE; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION, - LDLM_ENQUEUE, 1, size, NULL); + LDLM_ENQUEUE, 2, size, NULL); if (!req) RETURN(-ENOMEM); - /* get ready for the reply */ - repbufcnt = 1; + repbufcnt = 2; } else { LBUG(); RETURN(-EINVAL); } /* get ready for the reply */ - req->rq_replen = lustre_msg_size(repbufcnt, repsize); + ptlrpc_req_set_repsize(req, repbufcnt, repsize); mdc_get_rpc_lock(obddev->u.cli.cl_rpc_lock, it); rc = ldlm_cli_enqueue(exp, req, obddev->obd_namespace, res_id, @@ -393,8 +399,7 @@ int mdc_enqueue(struct obd_export *exp, /* Similarly, if we're going to replay this request, we don't want to * actually get a lock, just perform the intent. */ if (req->rq_transno || req->rq_replay) { - lockreq = lustre_msg_buf(req->rq_reqmsg, - MDS_REQ_INTENT_LOCKREQ_OFF, + lockreq = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, sizeof(*lockreq)); lockreq->lock_flags |= LDLM_FL_INTENT_ONLY; } @@ -427,12 +432,13 @@ int mdc_enqueue(struct obd_export *exp, LDLM_LOCK_PUT(lock); } - dlm_rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*dlm_rep)); - LASSERT(dlm_rep != NULL); /* checked by ldlm_cli_enqueue() */ - LASSERT_REPSWABBED(req, 0); /* swabbed by ldlm_cli_enqueue() */ + lockrep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, + sizeof(*lockrep)); + LASSERT(lockrep != NULL); /* checked by ldlm_cli_enqueue() */ + LASSERT_REPSWABBED(req, DLM_LOCKREPLY_OFF); /* swabbed by ldlm_cli_enqueue() */ - it->d.lustre.it_disposition = (int) dlm_rep->lock_policy_res1; - it->d.lustre.it_status = (int) dlm_rep->lock_policy_res2; + it->d.lustre.it_disposition = (int)lockrep->lock_policy_res1; + it->d.lustre.it_status = (int)lockrep->lock_policy_res2; it->d.lustre.it_lock_mode = lock_mode; it->d.lustre.it_data = req; @@ -443,12 +449,12 @@ int mdc_enqueue(struct obd_export *exp, it->it_op,it->d.lustre.it_disposition,it->d.lustre.it_status); /* We know what to expect, so we do any byte flipping required here */ - LASSERT(repbufcnt == 4 || repbufcnt == 1); - if (repbufcnt == 4) { + LASSERT(repbufcnt == 5 || repbufcnt == 2); + if (repbufcnt == 5) { struct mds_body *body; - body = lustre_swab_repbuf(req, 1, sizeof (*body), - lustre_swab_mds_body); + body = lustre_swab_repbuf(req, DLM_REPLY_REC_OFF, sizeof(*body), + lustre_swab_mds_body); if (body == NULL) { CERROR ("Can't swab mds_body\n"); RETURN (-EPROTO); @@ -457,8 +463,8 @@ int mdc_enqueue(struct obd_export *exp, if ((body->valid & OBD_MD_FLEASIZE) != 0) { /* The eadata is opaque; just check that it is there. * Eventually, obd_unpackmd() will check the contents */ - eadata = lustre_swab_repbuf(req, 2, body->eadatasize, - NULL); + eadata = lustre_swab_repbuf(req, DLM_REPLY_REC_OFF + 1, + body->eadatasize, NULL); if (eadata == NULL) { CERROR ("Missing/short eadata\n"); RETURN (-EPROTO); @@ -484,13 +490,13 @@ int mdc_enqueue(struct obd_export *exp, * large enough request buffer above we need to * reallocate it here to hold the actual LOV EA. */ if (it->it_op & IT_OPEN) { - int pos = MDS_REQ_INTENT_REC_OFF + 2; + int offset = DLM_INTENT_REC_OFF + 2; - if (req->rq_reqmsg->buflens[pos] < + if (lustre_msg_buflen(req->rq_reqmsg, offset) < body->eadatasize) mdc_realloc_openmsg(req, body, size); - lmm = lustre_msg_buf(req->rq_reqmsg, pos, + lmm = lustre_msg_buf(req->rq_reqmsg, offset, body->eadatasize); if (lmm) memcpy(lmm, eadata, body->eadatasize); @@ -642,7 +648,8 @@ int mdc_intent_lock(struct obd_export *exp, struct mdc_op_data *op_data, if (rc) RETURN(rc); - mds_body = lustre_msg_buf(request->rq_repmsg, 1, sizeof(*mds_body)); + mds_body = lustre_msg_buf(request->rq_repmsg, DLM_REPLY_REC_OFF, + sizeof(*mds_body)); LASSERT(mds_body != NULL); /* mdc_enqueue checked */ LASSERT_REPSWABBED(request, 1); /* mdc_enqueue swabbed */ diff --git a/lustre/mdc/mdc_reint.c b/lustre/mdc/mdc_reint.c index ff11d94..c5f41c1 100644 --- a/lustre/mdc/mdc_reint.c +++ b/lustre/mdc/mdc_reint.c @@ -51,7 +51,8 @@ static int mdc_reint(struct ptlrpc_request *request, mdc_put_rpc_lock(rpc_lock, NULL); if (rc) CDEBUG(D_INFO, "error in handling %d\n", rc); - else if (!lustre_swab_repbuf(request, 0, sizeof(struct mds_body), + else if (!lustre_swab_repbuf(request, REPLY_REC_OFF, + sizeof(struct mds_body), lustre_swab_mds_body)) { CERROR ("Can't unpack mds_body\n"); rc = -EPROTO; @@ -73,8 +74,9 @@ int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data, struct mds_rec_setattr *rec; struct mdc_rpc_lock *rpc_lock; struct obd_device *obd = exp->exp_obd; - int size[] = { sizeof(*rec), ealen, ea2len}; - int rc, bufcount = 1; + int size[4] = { sizeof(struct ptlrpc_body), + sizeof(*rec), ealen, ea2len }; + int bufcount = 2, rc; ENTRY; LASSERT(iattr != NULL); @@ -100,10 +102,10 @@ int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data, if (iattr->ia_valid & (ATTR_MTIME | ATTR_CTIME)) CDEBUG(D_INODE, "setting mtime %lu, ctime %lu\n", LTIME_S(iattr->ia_mtime), LTIME_S(iattr->ia_ctime)); - mdc_setattr_pack(req, MDS_REQ_REC_OFF, data, iattr, ea, ealen, ea2, ea2len); + mdc_setattr_pack(req, REQ_REC_OFF, data, iattr, ea, ealen, ea2, ea2len); - size[0] = sizeof(struct mds_body); - req->rq_replen = lustre_msg_size(1, size); + size[REPLY_REC_OFF] = sizeof(struct mds_body); + ptlrpc_req_set_repsize(req, 2, size); rc = mdc_reint(req, rpc_lock, LUSTRE_IMP_FULL); *request = req; @@ -119,8 +121,10 @@ int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data, { struct obd_device *obd = exp->exp_obd; struct ptlrpc_request *req; - int size[] = { sizeof(struct mds_rec_create), op_data->namelen + 1, 0}; - int rc, level, bufcount = 2; + int level, bufcount = 3, rc; + int size[4] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_rec_create), + op_data->namelen + 1 }; ENTRY; if (data && datalen) { @@ -135,11 +139,11 @@ int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data, /* mdc_create_pack fills msg->bufs[1] with name * and msg->bufs[2] with tgt, for symlinks or lov MD data */ - mdc_create_pack(req, MDS_REQ_REC_OFF, op_data, data, datalen, mode, - uid, gid, cap_effective, rdev); + mdc_create_pack(req, REQ_REC_OFF, op_data, data, datalen, mode, uid, + gid, cap_effective, rdev); - size[0] = sizeof(struct mds_body); - req->rq_replen = lustre_msg_size(1, size); + size[REPLY_REC_OFF] = sizeof(struct mds_body); + ptlrpc_req_set_repsize(req, 2, size); level = LUSTRE_IMP_FULL; resend: @@ -151,7 +155,7 @@ int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data, } if (!rc) - mdc_store_inode_generation(req, 0, 0); + mdc_store_inode_generation(req, REQ_REC_OFF, REPLY_REC_OFF); *request = req; RETURN(rc); @@ -162,22 +166,25 @@ int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data, { struct obd_device *obd = class_exp2obd(exp); struct ptlrpc_request *req = *request; - int rc, size[] = { sizeof(struct mds_rec_unlink), data->namelen + 1, 0}; + int size[4] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_rec_unlink), + data->namelen + 1 }; + int rc; ENTRY; LASSERT(req == NULL); req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_REINT, 2, size, NULL); + MDS_REINT, 3, size, NULL); if (req == NULL) RETURN(-ENOMEM); *request = req; - size[0] = sizeof(struct mds_body); - size[1] = obd->u.cli.cl_max_mds_easize; - size[2] = obd->u.cli.cl_max_mds_cookiesize; - req->rq_replen = lustre_msg_size(3, size); + size[REPLY_REC_OFF] = sizeof(struct mds_body); + size[REPLY_REC_OFF + 1] = obd->u.cli.cl_max_mds_easize; + size[REPLY_REC_OFF + 2] = obd->u.cli.cl_max_mds_cookiesize; + ptlrpc_req_set_repsize(req, 4, size); - mdc_unlink_pack(req, MDS_REQ_REC_OFF, data); + mdc_unlink_pack(req, REQ_REC_OFF, data); rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL); if (rc == -ERESTARTSYS) @@ -190,18 +197,21 @@ int mdc_link(struct obd_export *exp, struct mdc_op_data *data, { struct obd_device *obd = exp->exp_obd; struct ptlrpc_request *req; - int rc, size[] = { sizeof(struct mds_rec_link), data->namelen + 1}; + int size[3] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_rec_link), + data->namelen + 1 }; + int rc; ENTRY; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_REINT, 2, size, NULL); + MDS_REINT, 3, size, NULL); if (req == NULL) RETURN(-ENOMEM); - mdc_link_pack(req, MDS_REQ_REC_OFF, data); + mdc_link_pack(req, REQ_REC_OFF, data); - size[0] = sizeof(struct mds_body); - req->rq_replen = lustre_msg_size(1, size); + size[REPLY_REC_OFF] = sizeof(struct mds_body); + ptlrpc_req_set_repsize(req, 2, size); rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL); *request = req; @@ -217,20 +227,24 @@ int mdc_rename(struct obd_export *exp, struct mdc_op_data *data, { struct obd_device *obd = exp->exp_obd; struct ptlrpc_request *req; - int rc, size[] = { sizeof(struct mds_rec_rename), oldlen +1, newlen +1}; + int size[4] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_rec_rename), + oldlen + 1, + newlen + 1 }; + int rc; ENTRY; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_REINT, 3, size, NULL); + MDS_REINT, 4, size, NULL); if (req == NULL) RETURN(-ENOMEM); - mdc_rename_pack(req, MDS_REQ_REC_OFF, data, old, oldlen, new, newlen); + mdc_rename_pack(req, REQ_REC_OFF, data, old, oldlen, new, newlen); - size[0] = sizeof(struct mds_body); - size[1] = obd->u.cli.cl_max_mds_easize; - size[2] = obd->u.cli.cl_max_mds_cookiesize; - req->rq_replen = lustre_msg_size(3, size); + size[REPLY_REC_OFF] = sizeof(struct mds_body); + size[REPLY_REC_OFF + 1] = obd->u.cli.cl_max_mds_easize; + size[REPLY_REC_OFF + 2] = obd->u.cli.cl_max_mds_cookiesize; + ptlrpc_req_set_repsize(req, 4, size); rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL); *request = req; diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 593ac4b..a6b190b 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -54,25 +54,24 @@ static int send_getstatus(struct obd_import *imp, struct ll_fid *rootfid, int level, int msg_flags) { struct ptlrpc_request *req; - int rc, size[] = { [MDS_REQ_REC_OFF] = sizeof(struct mds_body) }; + struct mds_body *body; + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; - req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_GETSTATUS, - 1, size, NULL); + req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_GETSTATUS, 2, size, + NULL); if (!req) GOTO(out, rc = -ENOMEM); req->rq_send_state = level; - req->rq_replen = lustre_msg_size(1, size); + ptlrpc_req_set_repsize(req, 2, size); - mdc_pack_req_body(req, MDS_REQ_REC_OFF, 0, NULL, 0); - req->rq_reqmsg->flags |= msg_flags; + mdc_pack_req_body(req, REQ_REC_OFF, 0, NULL, 0); + lustre_msg_add_flags(req->rq_reqmsg, msg_flags); rc = ptlrpc_queue_wait(req); if (!rc) { - struct mds_body *body; - - body = lustre_swab_repbuf(req, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_mds_body); if (body == NULL) { CERROR ("Can't extract mds_body\n"); @@ -83,8 +82,9 @@ static int send_getstatus(struct obd_import *imp, struct ll_fid *rootfid, CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64 ", last_xid="LPU64"\n", - rootfid->id, req->rq_repmsg->last_committed, - req->rq_repmsg->last_xid); + rootfid->id, + lustre_msg_get_last_committed(req->rq_repmsg), + lustre_msg_get_last_xid(req->rq_repmsg)); } EXIT; @@ -105,10 +105,9 @@ int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size, unsigned int acl_size, struct ptlrpc_request *req) { struct mds_body *body; - void *eadata; - int rc; - int size[3] = {sizeof(*body)}; - int bufcount = 1; + void *eadata; + int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int bufcount = 2, rc; ENTRY; /* request message already built */ @@ -123,14 +122,14 @@ int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size, CDEBUG(D_INODE, "reserved %u bytes for ACL\n", acl_size); } - req->rq_replen = lustre_msg_size(bufcount, size); + ptlrpc_req_set_repsize(req, bufcount, size); rc = ptlrpc_queue_wait(req); if (rc != 0) RETURN (rc); - body = lustre_swab_repbuf (req, 0, sizeof (*body), - lustre_swab_mds_body); + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), + lustre_swab_mds_body); if (body == NULL) { CERROR ("Can't unpack mds_body\n"); RETURN (-EPROTO); @@ -138,10 +137,11 @@ int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size, CDEBUG(D_NET, "mode: %o\n", body->mode); - LASSERT_REPSWAB (req, 1); + LASSERT_REPSWAB(req, REPLY_REC_OFF + 1); if (body->eadatasize != 0) { /* reply indicates presence of eadata; check it's there... */ - eadata = lustre_msg_buf (req->rq_repmsg, 1, body->eadatasize); + eadata = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, + body->eadatasize); if (eadata == NULL) { CERROR ("Missing/short eadata\n"); RETURN (-EPROTO); @@ -166,8 +166,7 @@ int mdc_getattr(struct obd_export *exp, struct ll_fid *fid, struct ptlrpc_request **request) { struct ptlrpc_request *req; - struct mds_body *body; - int size = sizeof(*body); + int size[2] = { sizeof(struct ptlrpc_body), sizeof(struct mds_body) }; int acl_size = 0, rc; ENTRY; @@ -175,11 +174,11 @@ int mdc_getattr(struct obd_export *exp, struct ll_fid *fid, * to do the lookup in the first place. */ req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_GETATTR, 1, &size, NULL); + MDS_GETATTR, 2, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); - mdc_pack_req_body(req, MDS_REQ_REC_OFF, valid, fid, ea_size); + mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, ea_size); /* currently only root inode will call us with FLACL */ if (valid & OBD_MD_FLACL) @@ -197,23 +196,25 @@ int mdc_getattr(struct obd_export *exp, struct ll_fid *fid, int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid, const char *filename, int namelen, unsigned long valid, - unsigned int ea_len, struct ptlrpc_request **request) + unsigned int ea_size, struct ptlrpc_request **request) { struct ptlrpc_request *req; - int rc, size[] = { sizeof(struct mds_body), namelen }; + struct mds_body *body; + int rc, size[3] = { sizeof(struct ptlrpc_body), sizeof(*body), namelen}; ENTRY; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_GETATTR_NAME, 2, size, NULL); + MDS_GETATTR_NAME, 3, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); - mdc_pack_req_body(req, MDS_REQ_REC_OFF, valid, fid, ea_len); + mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, ea_size); - LASSERT (strnlen (filename, namelen) == namelen - 1); - memcpy(lustre_msg_buf(req->rq_reqmsg, 1, namelen), filename, namelen); + LASSERT(strnlen(filename, namelen) == namelen - 1); + memcpy(lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, namelen), + filename, namelen); - rc = mdc_getattr_common(exp, ea_len, 0, req); + rc = mdc_getattr_common(exp, ea_size, 0, req); if (rc != 0) { ptlrpc_req_finished (req); req = NULL; @@ -231,8 +232,8 @@ int mdc_xattr_common(struct obd_export *exp, struct ll_fid *fid, { struct ptlrpc_request *req; struct mds_body *body; - int size[3] = {sizeof(*body)}, bufcnt = 1; - int xattr_namelen = 0, rc; + int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int rc, xattr_namelen = 0, bufcnt = 2, offset; void *tmp; ENTRY; @@ -245,36 +246,37 @@ int mdc_xattr_common(struct obd_export *exp, struct ll_fid *fid, size[bufcnt++] = input_size; } - req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, opcode, - bufcnt, size, NULL); + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, + opcode, bufcnt, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); /* request data */ - body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body)); - mdc_pack_req_body(req, MDS_REQ_REC_OFF, valid, fid, output_size); + mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, output_size); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); body->flags = flags; + offset = REQ_REC_OFF + 1; + if (xattr_name) { - tmp = lustre_msg_buf(req->rq_reqmsg, 1, xattr_namelen); + tmp = lustre_msg_buf(req->rq_reqmsg, offset++, xattr_namelen); memcpy(tmp, xattr_name, xattr_namelen); } if (input_size) { - tmp = lustre_msg_buf(req->rq_reqmsg, bufcnt - 1, input_size); + tmp = lustre_msg_buf(req->rq_reqmsg, offset++, input_size); memcpy(tmp, input, input_size); } /* reply buffers */ if (opcode == MDS_GETXATTR) { - size[0] = sizeof(*body); - bufcnt = 1; + bufcnt = 2; } else { - bufcnt = 0; + bufcnt = 1; } if (output_size) size[bufcnt++] = output_size; - req->rq_replen = lustre_msg_size(bufcnt, size); + ptlrpc_req_set_repsize(req, bufcnt, size); /* make rpc */ if (opcode == MDS_SETXATTR) @@ -289,7 +291,7 @@ int mdc_xattr_common(struct obd_export *exp, struct ll_fid *fid, GOTO(err_out, rc); if (opcode == MDS_GETXATTR) { - body = lustre_swab_repbuf(req, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_mds_body); if (body == NULL) { CERROR ("Can't unpack mds_body\n"); @@ -363,9 +365,9 @@ int mdc_unpack_acl(struct obd_export *exp, struct ptlrpc_request *req, buf = lustre_msg_buf(req->rq_repmsg, offset, body->aclsize); if (!buf) { CERROR("aclsize %u, bufcount %u, bufsize %u\n", - body->aclsize, req->rq_repmsg->bufcount, - (req->rq_repmsg->bufcount <= offset) ? -1 : - req->rq_repmsg->buflens[offset]); + body->aclsize, lustre_msg_bufcount(req->rq_repmsg), + (lustre_msg_bufcount(req->rq_repmsg) <= offset) ? + -1 : lustre_msg_buflen(req->rq_repmsg, offset)); return -EPROTO; } @@ -402,7 +404,7 @@ int mdc_req2lustre_md(struct ptlrpc_request *req, int offset, md->body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*md->body)); LASSERT (md->body != NULL); - LASSERT_REPSWABBED (req, offset); + LASSERT_REPSWABBED(req, offset); offset++; if (md->body->valid & OBD_MD_FLEASIZE) { @@ -418,7 +420,7 @@ int mdc_req2lustre_md(struct ptlrpc_request *req, int offset, lmmsize = md->body->eadatasize; lmm = lustre_msg_buf(req->rq_repmsg, offset, lmmsize); LASSERT (lmm != NULL); - LASSERT_REPSWABBED (req, offset); + LASSERT_REPSWABBED(req, offset); rc = obd_unpackmd(exp, &md->lsm, lmm, lmmsize); if (rc < 0) @@ -487,7 +489,8 @@ static void mdc_replay_open(struct ptlrpc_request *req) struct mds_body *body; ENTRY; - body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body); + body = lustre_swab_repbuf(req, DLM_REPLY_REC_OFF, sizeof(*body), + lustre_swab_mds_body); LASSERT (body != NULL); if (mod == NULL) { @@ -511,9 +514,8 @@ static void mdc_replay_open(struct ptlrpc_request *req) close_req = mod->mod_close_req; if (close_req != NULL) { struct mds_body *close_body; - LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE); - close_body = lustre_msg_buf(close_req->rq_reqmsg, - MDS_REQ_REC_OFF, + LASSERT(lustre_msg_get_opc(close_req->rq_reqmsg) == MDS_CLOSE); + close_body = lustre_msg_buf(close_req->rq_reqmsg, REQ_REC_OFF, sizeof(*close_body)); if (och != NULL) LASSERT(!memcmp(&old, &close_body->handle, sizeof old)); @@ -530,16 +532,17 @@ void mdc_set_open_replay_data(struct obd_client_handle *och, { struct mdc_open_data *mod; struct mds_rec_create *rec = lustre_msg_buf(open_req->rq_reqmsg, - MDS_REQ_INTENT_REC_OFF, + DLM_INTENT_REC_OFF, sizeof(*rec)); - struct mds_body *body = lustre_msg_buf(open_req->rq_repmsg, 1, + struct mds_body *body = lustre_msg_buf(open_req->rq_repmsg, + DLM_REPLY_REC_OFF, sizeof(*body)); - LASSERT(body != NULL); /* incoming message in my byte order (it's been swabbed) */ LASSERT(rec != NULL); + LASSERT_REPSWABBED(open_req, DLM_REPLY_REC_OFF); /* outgoing messages always in my byte order */ - LASSERT_REPSWABBED(open_req, 1); + LASSERT(body != NULL); OBD_ALLOC(mod, sizeof(*mod)); if (mod == NULL) { @@ -612,16 +615,18 @@ int mdc_close(struct obd_export *exp, struct obdo *oa, struct obd_client_handle *och, struct ptlrpc_request **request) { struct obd_device *obd = class_exp2obd(exp); - int size[] = { sizeof(struct mds_body) }; - int rc, repsize[] = { sizeof(struct mds_body), - obd->u.cli.cl_max_mds_easize, - obd->u.cli.cl_max_mds_cookiesize}; + int reqsize[2] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_body) }; + int rc, repsize[4] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_body), + obd->u.cli.cl_max_mds_easize, + obd->u.cli.cl_max_mds_cookiesize }; struct ptlrpc_request *req; struct mdc_open_data *mod; ENTRY; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_CLOSE, 1, size, NULL); + MDS_CLOSE, 2, reqsize, NULL); if (req == NULL) GOTO(out, rc = -ENOMEM); @@ -644,9 +649,9 @@ int mdc_close(struct obd_export *exp, struct obdo *oa, CDEBUG(D_HA, "couldn't find open req; expecting close error\n"); } - mdc_close_pack(req, MDS_REQ_REC_OFF, oa, oa->o_valid, och); + mdc_close_pack(req, REQ_REC_OFF, oa, oa->o_valid, och); - req->rq_replen = lustre_msg_size(3, repsize); + ptlrpc_req_set_repsize(req, 4, repsize); req->rq_commit_cb = mdc_commit_close; LASSERT(req->rq_cb_data == NULL); req->rq_cb_data = mod; @@ -661,8 +666,8 @@ int mdc_close(struct obd_export *exp, struct obdo *oa, if (rc == 0) rc = req->rq_status ? req->rq_status : -EIO; } else if (rc == 0) { - rc = req->rq_repmsg->status; - if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) { + rc = lustre_msg_get_status(req->rq_repmsg); + if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) { DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err " "= %d", rc); if (rc > 0) @@ -671,7 +676,8 @@ int mdc_close(struct obd_export *exp, struct obdo *oa, CERROR("Unexpected: can't find mdc_open_data, but the " "close succeeded. Please tell CFS.\n"); } - if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body), + if (!lustre_swab_repbuf(req, REPLY_REC_OFF, + sizeof(struct mds_body), lustre_swab_mds_body)) { CERROR("Error unpacking mds_body\n"); rc = -EPROTO; @@ -691,15 +697,15 @@ int mdc_done_writing(struct obd_export *exp, struct obdo *obdo) { struct ptlrpc_request *req; struct mds_body *body; - int rc, size[] = { [MDS_REQ_REC_OFF] = sizeof(*body) }; + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_DONE_WRITING, 1, size, NULL); + MDS_DONE_WRITING, 2, size, NULL); if (req == NULL) RETURN(-ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); mdc_pack_fid(&body->fid1, obdo->o_id, 0, obdo->o_mode); body->size = obdo->o_size; body->blocks = obdo->o_blocks; @@ -707,7 +713,7 @@ int mdc_done_writing(struct obd_export *exp, struct obdo *obdo) body->valid = obdo->o_valid; // memcpy(&body->handle, &och->och_fh, sizeof(body->handle)); - req->rq_replen = lustre_msg_size(1, size); + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); ptlrpc_req_finished(req); @@ -721,13 +727,13 @@ int mdc_readpage(struct obd_export *exp, struct ll_fid *fid, __u64 offset, struct ptlrpc_request *req = NULL; struct ptlrpc_bulk_desc *desc = NULL; struct mds_body *body; - int rc, size[] = { sizeof(*body) }; + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; CDEBUG(D_INODE, "inode: "LPU64"\n", fid->id); - req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE, - 1, size, NULL); + req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE, 2, size, + NULL); if (req == NULL) GOTO(out, rc = -ENOMEM); @@ -741,13 +747,13 @@ int mdc_readpage(struct obd_export *exp, struct ll_fid *fid, __u64 offset, ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE); - mdc_readdir_pack(req, MDS_REQ_REC_OFF, offset, PAGE_CACHE_SIZE, fid); + mdc_readdir_pack(req, REQ_REC_OFF, offset, PAGE_CACHE_SIZE, fid); - req->rq_replen = lustre_msg_size(1, size); + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); if (rc == 0) { - body = lustre_swab_repbuf(req, 0, sizeof (*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_mds_body); if (body == NULL) { CERROR("Can't unpack mds_body\n"); @@ -857,8 +863,8 @@ int mdc_set_info_async(struct obd_export *exp, obd_count keylen, } if (KEY_IS("read-only")) { struct ptlrpc_request *req; - int size[2] = {keylen, vallen}; - char *bufs[2] = {key, val}; + int size[3] = { sizeof(struct ptlrpc_body), keylen, vallen }; + char *bufs[3] = { NULL, key, val }; if (vallen != sizeof(int)) RETURN(-EINVAL); @@ -871,12 +877,12 @@ int mdc_set_info_async(struct obd_export *exp, obd_count keylen, ~OBD_CONNECT_RDONLY; } - req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, - MDS_SET_INFO, 2, size, bufs); + req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_SET_INFO, + 3, size, bufs); if (req == NULL) RETURN(-ENOMEM); - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); if (set) { rc = 0; ptlrpc_set_add_req(set, req); @@ -917,7 +923,7 @@ static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs, { struct ptlrpc_request *req; struct obd_statfs *msfs; - int rc, size = sizeof(*msfs); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*msfs) }; ENTRY; /* We could possibly pass max_age in the request (as an absolute @@ -927,24 +933,25 @@ static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs, * is not so great if request processing is slow, while absolute * timestamps are not ideal because they need time synchronization. */ req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION, - MDS_STATFS, 0, NULL, NULL); + MDS_STATFS, 1, NULL, NULL); if (!req) RETURN(-ENOMEM); - req->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),lustre_swab_obd_statfs); + msfs = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*msfs), + lustre_swab_obd_statfs); if (msfs == NULL) { CERROR("Can't unpack obd_statfs\n"); GOTO(out, rc = -EPROTO); } - memcpy(osfs, msfs, sizeof (*msfs)); + memcpy(osfs, msfs, sizeof(*msfs)); EXIT; out: ptlrpc_req_finished(req); @@ -957,19 +964,19 @@ static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type, { struct ptlrpc_request *req; struct mds_body *body; - int rc, size[] = { [MDS_REQ_REC_OFF] = sizeof(struct mds_body) }; + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_PIN, 1, size, NULL); + MDS_PIN, 2, size, NULL); if (req == NULL) RETURN(-ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); mdc_pack_fid(&body->fid1, ino, gen, type); body->flags = flag; - req->rq_replen = lustre_msg_size(1, size); + ptlrpc_req_set_repsize(req, 2, size); mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); rc = ptlrpc_queue_wait(req); @@ -980,7 +987,8 @@ static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type, RETURN(rc); } - body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body); + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), + lustre_swab_mds_body); if (body == NULL) { ptlrpc_req_finished(req); RETURN(rc); @@ -1004,22 +1012,22 @@ static int mdc_unpin(struct obd_export *exp, { struct ptlrpc_request *req; struct mds_body *body; - int rc, size[] = { [MDS_REQ_REC_OFF] = sizeof(struct mds_body) }; + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC) RETURN(0); req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_CLOSE, 1, size, NULL); + MDS_CLOSE, 2, size, NULL); if (req == NULL) RETURN(-ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); memcpy(&body->handle, &handle->och_fh, sizeof(body->handle)); body->flags = flag; - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); rc = ptlrpc_queue_wait(req); mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); @@ -1037,17 +1045,18 @@ int mdc_sync(struct obd_export *exp, struct ll_fid *fid, struct ptlrpc_request **request) { struct ptlrpc_request *req; - int rc, size[] = { [MDS_REQ_REC_OFF] = sizeof(struct mds_body) }; + int size[2] = { sizeof(struct ptlrpc_body), sizeof(struct mds_body) }; + int rc; ENTRY; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, - MDS_SYNC, 1, size, NULL); + MDS_SYNC, 2, size, NULL); if (!req) RETURN(rc = -ENOMEM); - mdc_pack_req_body(req, MDS_REQ_REC_OFF, 0, fid, 0); + mdc_pack_req_body(req, REQ_REC_OFF, 0, fid, 0); - req->rq_replen = lustre_msg_size(1, size); + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); if (rc || request == NULL) diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index 5f2e87d..86c8023 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -420,7 +420,7 @@ static int mds_destroy_export(struct obd_export *export) /* child orphan sem protects orphan_dec_test and * is_orphan race, mds_mfd_close drops it */ MDS_DOWN_WRITE_ORPHAN_SEM(dentry->d_inode); - rc = mds_mfd_close(NULL, MDS_REQ_REC_OFF, obd, mfd, + rc = mds_mfd_close(NULL, REQ_REC_OFF, obd, mfd, !(export->exp_flags & OBD_OPT_FAILOVER)); if (rc) @@ -470,17 +470,17 @@ static int mds_getstatus(struct ptlrpc_request *req) { struct mds_obd *mds = mds_req2mds(req); struct mds_body *body; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) { - CERROR("mds: out of memory for message: size=%d\n", size); + CERROR("mds: out of memory for message\n"); req->rq_status = -ENOMEM; /* superfluous? */ RETURN(-ENOMEM); } - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body)); memcpy(&body->fid1, &mds->mds_rootfid, sizeof(body->fid1)); /* the last_committed and last_xid fields are filled in for all @@ -545,7 +545,7 @@ int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset, inode->i_ino); RETURN(0); } - lmm_size = msg->buflens[offset]; + lmm_size = lustre_msg_buflen(msg, offset); /* I don't really like this, but it is a sanity check on the client * MD request. However, if the client doesn't know how much space @@ -580,7 +580,7 @@ int mds_pack_posix_acl(struct inode *inode, struct lustre_msg *repmsg, ENTRY; LASSERT(repbody->aclsize == 0); - LASSERT(repmsg->bufcount > repoff); + LASSERT(lustre_msg_bufcount(repmsg) > repoff); buflen = lustre_msg_buflen(repmsg, repoff); if (!buflen) @@ -656,7 +656,7 @@ static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry, int len; LASSERT (symname != NULL); /* caller prepped reply */ - len = req->rq_repmsg->buflens[reply_off]; + len = lustre_msg_buflen(req->rq_repmsg, reply_off); rc = inode->i_op->readlink(dentry, symname, len); if (rc < 0) { @@ -706,10 +706,13 @@ static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct inode *inode, { struct mds_obd *mds = mds_req2mds(req); struct mds_body *body; - int rc, size[3] = {sizeof(*body)}, bufcount = 1; + int rc, bufcount = 2; + int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; - body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*body)); + LASSERT(offset == REQ_REC_OFF); /* non-intent */ + + body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body)); LASSERT(body != NULL); /* checked by caller */ LASSERT_REQSWABBED(req, offset); /* swabbed by caller */ @@ -786,7 +789,7 @@ static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct inode *inode, RETURN(0); } -static int mds_getattr_lock(int offset, struct ptlrpc_request *req, +static int mds_getattr_lock(struct ptlrpc_request *req, int offset, int child_part, struct lustre_handle *child_lockh) { struct obd_device *obd = req->rq_export->exp_obd; @@ -805,7 +808,6 @@ static int mds_getattr_lock(int offset, struct ptlrpc_request *req, LASSERT(!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME)); /* Swab now, before anyone looks inside the request */ - body = lustre_swab_reqbuf(req, offset, sizeof(*body), lustre_swab_mds_body); if (body == NULL) { @@ -829,11 +831,12 @@ static int mds_getattr_lock(int offset, struct ptlrpc_request *req, if (rc) GOTO(cleanup, rc); - LASSERT (offset == MDS_REQ_REC_OFF || offset == MDS_REQ_INTENT_REC_OFF); + LASSERT(offset == REQ_REC_OFF || offset == DLM_INTENT_REC_OFF); /* if requests were at offset 2, the getattr reply goes back at 1 */ - if (offset == MDS_REQ_INTENT_REC_OFF) { - rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep)); - offset = 1; + if (offset == DLM_INTENT_REC_OFF) { + rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, + sizeof(*rep)); + offset = DLM_REPLY_REC_OFF; } push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc); @@ -948,7 +951,7 @@ static int mds_getattr_lock(int offset, struct ptlrpc_request *req, mds_exit_ucred(&uc, mds); if (req->rq_reply_state == NULL) { req->rq_status = rc; - lustre_pack_reply(req, 0, NULL, NULL); + lustre_pack_reply(req, 1, NULL, NULL); } } return rc; @@ -961,7 +964,7 @@ static int mds_getattr(struct ptlrpc_request *req, int offset) struct lvfs_run_ctxt saved; struct dentry *de; struct mds_body *body; - struct lvfs_ucred uc = {NULL,}; + struct lvfs_ucred uc = { NULL, }; int rc = 0; ENTRY; @@ -987,7 +990,7 @@ static int mds_getattr(struct ptlrpc_request *req, int offset) GOTO(out_pop, rc); } - req->rq_status = mds_getattr_internal(obd, de, req, body, 0); + req->rq_status = mds_getattr_internal(obd, de, req, body,REPLY_REC_OFF); l_dput(de); GOTO(out_pop, rc); @@ -996,7 +999,7 @@ out_pop: out_ucred: if (req->rq_reply_state == NULL) { req->rq_status = rc; - lustre_pack_reply(req, 0, NULL, NULL); + lustre_pack_reply(req, 1, NULL, NULL); } mds_exit_ucred(&uc, mds); return rc; @@ -1019,21 +1022,23 @@ static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs, static int mds_statfs(struct ptlrpc_request *req) { struct obd_device *obd = req->rq_export->exp_obd; - int rc, size = sizeof(struct obd_statfs); + int rc, size[2] = { sizeof(struct ptlrpc_body), + sizeof(struct obd_statfs) }; ENTRY; /* This will trigger a watchdog timeout */ OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP, (MDS_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) { CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc); GOTO(out, rc); } /* We call this so that we can cache a bit - 1 jiffie worth */ - rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, 0, size), + rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + size[REPLY_REC_OFF]), jiffies - HZ); if (rc) { CERROR("mds_obd_statfs failed: rc %d\n", rc); @@ -1051,14 +1056,15 @@ static int mds_sync(struct ptlrpc_request *req, int offset) struct obd_device *obd = req->rq_export->exp_obd; struct mds_obd *mds = &obd->u.mds; struct mds_body *body; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_mds_body); + body = lustre_swab_reqbuf(req, offset, sizeof(*body), + lustre_swab_mds_body); if (body == NULL) GOTO(out, rc = -EFAULT); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) { CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc); GOTO(out, rc); @@ -1079,7 +1085,8 @@ static int mds_sync(struct ptlrpc_request *req, int offset) if (de->d_inode->i_fop && de->d_inode->i_fop->fsync) rc = de->d_inode->i_fop->fsync(NULL, de, 1); if (rc == 0) { - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); mds_pack_inode2fid(&body->fid1, de->d_inode); mds_pack_inode2body(body, de->d_inode); } @@ -1106,14 +1113,14 @@ static int mds_readpage(struct ptlrpc_request *req, int offset) struct file *file; struct mds_body *body, *repbody; struct lvfs_run_ctxt saved; - int rc, size = sizeof(*repbody); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) }; struct lvfs_ucred uc = {NULL,}; ENTRY; if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) RETURN(-ENOMEM); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) { CERROR("error packing readpage reply: rc %d\n", rc); GOTO(out, rc); @@ -1124,7 +1131,7 @@ static int mds_readpage(struct ptlrpc_request *req, int offset) if (body == NULL) GOTO (out, rc = -EFAULT); - rc = mds_init_ucred(&uc, req, 0); + rc = mds_init_ucred(&uc, req, offset); if (rc) GOTO(out, rc); @@ -1154,7 +1161,8 @@ static int mds_readpage(struct ptlrpc_request *req, int offset) GOTO(out_file, rc = -EFAULT); } - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); repbody->size = file->f_dentry->d_inode->i_size; repbody->valid = OBD_MD_FLSIZE; @@ -1200,7 +1208,7 @@ int mds_reint(struct ptlrpc_request *req, int offset, static int mds_filter_recovery_request(struct ptlrpc_request *req, struct obd_device *obd, int *process) { - switch (req->rq_reqmsg->opc) { + switch (lustre_msg_get_opc(req->rq_reqmsg)) { case MDS_CONNECT: /* This will never get here, but for completeness. */ case OST_CONNECT: /* This will never get here, but for completeness. */ case MDS_DISCONNECT: @@ -1241,23 +1249,23 @@ static int mds_set_info_rpc(struct obd_export *exp, struct ptlrpc_request *req) int keylen, rc = 0; ENTRY; - key = lustre_msg_buf(req->rq_reqmsg, 0, 1); + key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1); if (key == NULL) { DEBUG_REQ(D_HA, req, "no set_info key"); RETURN(-EFAULT); } - keylen = req->rq_reqmsg->buflens[0]; + keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF); - val = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*val)); + val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*val)); if (val == NULL) { DEBUG_REQ(D_HA, req, "no set_info val"); RETURN(-EFAULT); } - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) RETURN(rc); - req->rq_repmsg->status = 0; + lustre_msg_set_status(req->rq_repmsg, 0); if (keylen < strlen("read-only") || memcmp(key, "read-only", keylen) != 0) @@ -1277,12 +1285,12 @@ static int mds_handle_quotacheck(struct ptlrpc_request *req) int rc; ENTRY; - oqctl = lustre_swab_reqbuf(req, 0, sizeof(*oqctl), + oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl), lustre_swab_obd_quotactl); if (oqctl == NULL) RETURN(-EPROTO); - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) { CERROR("mds: out of memory while packing quotacheck reply\n"); RETURN(rc); @@ -1295,19 +1303,19 @@ static int mds_handle_quotacheck(struct ptlrpc_request *req) static int mds_handle_quotactl(struct ptlrpc_request *req) { struct obd_quotactl *oqctl, *repoqc; - int rc, size = sizeof(*repoqc); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) }; ENTRY; - oqctl = lustre_swab_reqbuf(req, 0, sizeof(*oqctl), + oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl), lustre_swab_obd_quotactl); if (oqctl == NULL) RETURN(-EPROTO); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - repoqc = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repoqc)); + repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc)); req->rq_status = obd_quotactl(req->rq_export, oqctl); *repoqc = *oqctl; @@ -1318,19 +1326,16 @@ static int mds_msg_check_version(struct lustre_msg *msg) { int rc; - /* TODO: enable the below check while really introducing msg version. - * it's disabled because it will break compatibility with b1_4. - */ - return (0); - - switch (msg->opc) { + switch (lustre_msg_get_opc(msg)) { case MDS_CONNECT: case MDS_DISCONNECT: case OBD_PING: rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION); if (rc) CERROR("bad opc %u version %08x, expecting %08x\n", - msg->opc, msg->version, LUSTRE_OBD_VERSION); + lustre_msg_get_opc(msg), + lustre_msg_get_version(msg), + LUSTRE_OBD_VERSION); break; case MDS_GETSTATUS: case MDS_GETATTR: @@ -1352,7 +1357,9 @@ static int mds_msg_check_version(struct lustre_msg *msg) rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION); if (rc) CERROR("bad opc %u version %08x, expecting %08x\n", - msg->opc, msg->version, LUSTRE_MDS_VERSION); + lustre_msg_get_opc(msg), + lustre_msg_get_version(msg), + LUSTRE_MDS_VERSION); break; case LDLM_ENQUEUE: case LDLM_CONVERT: @@ -1361,22 +1368,27 @@ static int mds_msg_check_version(struct lustre_msg *msg) rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION); if (rc) CERROR("bad opc %u version %08x, expecting %08x\n", - msg->opc, msg->version, LUSTRE_DLM_VERSION); + lustre_msg_get_opc(msg), + lustre_msg_get_version(msg), + LUSTRE_DLM_VERSION); break; case OBD_LOG_CANCEL: case LLOG_ORIGIN_HANDLE_CREATE: case LLOG_ORIGIN_HANDLE_NEXT_BLOCK: - case LLOG_ORIGIN_HANDLE_PREV_BLOCK: case LLOG_ORIGIN_HANDLE_READ_HEADER: case LLOG_ORIGIN_HANDLE_CLOSE: + case LLOG_ORIGIN_HANDLE_DESTROY: + case LLOG_ORIGIN_HANDLE_PREV_BLOCK: case LLOG_CATINFO: rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION); if (rc) CERROR("bad opc %u version %08x, expecting %08x\n", - msg->opc, msg->version, LUSTRE_LOG_VERSION); + lustre_msg_get_opc(msg), + lustre_msg_get_version(msg), + LUSTRE_LOG_VERSION); break; default: - CERROR("MDS unknown opcode %d\n", msg->opc); + CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg)); rc = -ENOTSUPP; } return rc; @@ -1401,13 +1413,13 @@ int mds_handle(struct ptlrpc_request *req) } /* XXX identical to OST */ - if (req->rq_reqmsg->opc != MDS_CONNECT) { + if (lustre_msg_get_opc(req->rq_reqmsg) != MDS_CONNECT) { struct mds_export_data *med; int recovering, abort_recovery; if (req->rq_export == NULL) { CERROR("operation %d on unconnected MDS from %s\n", - req->rq_reqmsg->opc, + lustre_msg_get_opc(req->rq_reqmsg), libcfs_id2str(req->rq_peer)); req->rq_status = -ENOTCONN; GOTO(out, rc = -ENOTCONN); @@ -1447,7 +1459,7 @@ int mds_handle(struct ptlrpc_request *req) } } - switch (req->rq_reqmsg->opc) { + switch (lustre_msg_get_opc(req->rq_reqmsg)) { case MDS_CONNECT: DEBUG_REQ(D_INODE, req, "connect"); OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0); @@ -1475,7 +1487,7 @@ int mds_handle(struct ptlrpc_request *req) case MDS_GETATTR: DEBUG_REQ(D_INODE, req, "getattr"); OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0); - rc = mds_getattr(req, MDS_REQ_REC_OFF); + rc = mds_getattr(req, REQ_REC_OFF); break; case MDS_SETXATTR: @@ -1499,8 +1511,8 @@ int mds_handle(struct ptlrpc_request *req) * acquiring any new locks in mds_getattr_lock, so we don't * want to cancel. */ - rc = mds_getattr_lock(MDS_REQ_REC_OFF, req, - MDS_INODELOCK_UPDATE, &lockh); + rc = mds_getattr_lock(req, REQ_REC_OFF, MDS_INODELOCK_UPDATE, + &lockh); /* this non-intent call (from an ioctl) is special */ req->rq_status = rc; if (rc == 0 && lustre_handle_is_used(&lockh)) @@ -1516,7 +1528,7 @@ int mds_handle(struct ptlrpc_request *req) case MDS_READPAGE: DEBUG_REQ(D_INODE, req, "readpage"); OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0); - rc = mds_readpage(req, MDS_REQ_REC_OFF); + rc = mds_readpage(req, REQ_REC_OFF); if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) { RETURN(0); @@ -1525,11 +1537,13 @@ int mds_handle(struct ptlrpc_request *req) break; case MDS_REINT: { - __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, - sizeof (*opcp)); + __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, + sizeof(*opcp)); __u32 opc; - int size[] = { sizeof(struct mds_body), mds->mds_max_mdsize, - mds->mds_max_cookiesize}; + int size[4] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_body), + mds->mds_max_mdsize, + mds->mds_max_cookiesize }; int bufcount; /* NB only peek inside req now; mds_reint() will swab it */ @@ -1539,7 +1553,7 @@ int mds_handle(struct ptlrpc_request *req) break; } opc = *opcp; - if (lustre_msg_swabbed (req->rq_reqmsg)) + if (lustre_msg_swabbed(req->rq_reqmsg)) __swab32s(&opc); DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc, @@ -1550,17 +1564,17 @@ int mds_handle(struct ptlrpc_request *req) OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0); if (opc == REINT_UNLINK || opc == REINT_RENAME) - bufcount = 3; + bufcount = 4; else if (opc == REINT_OPEN) - bufcount = 2; + bufcount = 3; else - bufcount = 1; + bufcount = 2; rc = lustre_pack_reply(req, bufcount, size, NULL); if (rc) break; - rc = mds_reint(req, MDS_REQ_REC_OFF, NULL); + rc = mds_reint(req, REQ_REC_OFF, NULL); fail = OBD_FAIL_MDS_REINT_NET_REP; break; } @@ -1568,25 +1582,25 @@ int mds_handle(struct ptlrpc_request *req) case MDS_CLOSE: DEBUG_REQ(D_INODE, req, "close"); OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0); - rc = mds_close(req, MDS_REQ_REC_OFF); + rc = mds_close(req, REQ_REC_OFF); break; case MDS_DONE_WRITING: DEBUG_REQ(D_INODE, req, "done_writing"); OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0); - rc = mds_done_writing(req, MDS_REQ_REC_OFF); + rc = mds_done_writing(req, REQ_REC_OFF); break; case MDS_PIN: DEBUG_REQ(D_INODE, req, "pin"); OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0); - rc = mds_pin(req, MDS_REQ_REC_OFF); + rc = mds_pin(req, REQ_REC_OFF); break; case MDS_SYNC: DEBUG_REQ(D_INODE, req, "sync"); OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0); - rc = mds_sync(req, MDS_REQ_REC_OFF); + rc = mds_sync(req, REQ_REC_OFF); break; case MDS_SET_INFO: @@ -1680,10 +1694,10 @@ int mds_handle(struct ptlrpc_request *req) LASSERT(current->journal_info == NULL); /* If we're DISCONNECTing, the mds_export_data is already freed */ - if (!rc && req->rq_reqmsg->opc != MDS_DISCONNECT) { + if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != MDS_DISCONNECT) { struct mds_export_data *med = &req->rq_export->exp_mds_data; - req->rq_repmsg->last_xid = - le64_to_cpu(med->med_mcd->mcd_last_xid); + lustre_msg_set_last_xid(req->rq_repmsg, + le64_to_cpu(med->med_mcd->mcd_last_xid)); target_committed_to_req(req); } @@ -2225,7 +2239,7 @@ static void fixup_handle_for_resent_req(struct ptlrpc_request *req, int offset, struct obd_export *exp = req->rq_export; struct obd_device *obd = exp->exp_obd; struct ldlm_request *dlmreq = - lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*dlmreq)); + lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*dlmreq)); struct lustre_handle remote_hdl = dlmreq->lock_handle1; struct list_head *iter; @@ -2294,24 +2308,23 @@ static int mds_intent_policy(struct ldlm_namespace *ns, struct lustre_handle lockh = { 0 }; struct ldlm_lock *new_lock = NULL; int getattr_part = MDS_INODELOCK_UPDATE; - int repsize[4] = {sizeof(*rep), - sizeof(struct mds_body), - mds->mds_max_mdsize}; - int repbufcnt = 3, offset = MDS_REQ_INTENT_REC_OFF; - int rc; + int repsize[5] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREPLY_OFF] = sizeof(struct ldlm_reply), + [DLM_REPLY_REC_OFF] = sizeof(struct mds_body), + [DLM_REPLY_REC_OFF+1] = mds->mds_max_mdsize }; + int repbufcnt = 4, rc; ENTRY; LASSERT(req != NULL); - if (req->rq_reqmsg->bufcount <= MDS_REQ_INTENT_IT_OFF) { + if (lustre_msg_bufcount(req->rq_reqmsg) <= DLM_INTENT_IT_OFF) { /* No intent was provided */ - int size = sizeof(struct ldlm_reply); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, repsize, NULL); LASSERT(rc == 0); RETURN(0); } - it = lustre_swab_reqbuf(req, MDS_REQ_INTENT_IT_OFF, sizeof(*it), + it = lustre_swab_reqbuf(req, DLM_INTENT_IT_OFF, sizeof(*it), lustre_swab_ldlm_intent); if (it == NULL) { CERROR("Intent missing\n"); @@ -2331,7 +2344,7 @@ static int mds_intent_policy(struct ldlm_namespace *ns, if (rc) RETURN(req->rq_status = rc); - rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep)); + rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, sizeof(*rep)); intent_set_disposition(rep, DISP_IT_EXECD); @@ -2339,11 +2352,12 @@ static int mds_intent_policy(struct ldlm_namespace *ns, switch ((long)it->opc) { case IT_OPEN: case IT_CREAT|IT_OPEN: - fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF, - lock, NULL, &lockh); + fixup_handle_for_resent_req(req, DLM_LOCKREQ_OFF, lock, NULL, + &lockh); /* XXX swab here to assert that an mds_open reint * packet is following */ - rep->lock_policy_res2 = mds_reint(req, offset, &lockh); + rep->lock_policy_res2 = mds_reint(req, DLM_INTENT_REC_OFF, + &lockh); #if 0 /* We abort the lock if the lookup was negative and * we did not make it to the OPEN portion */ @@ -2359,8 +2373,8 @@ static int mds_intent_policy(struct ldlm_namespace *ns, case IT_GETATTR: getattr_part |= MDS_INODELOCK_LOOKUP; case IT_READDIR: - fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF, - lock, &new_lock, &lockh); + fixup_handle_for_resent_req(req, DLM_LOCKREQ_OFF, lock, + &new_lock, &lockh); /* INODEBITS_INTEROP: if this lock was converted from a * plain lock (client does not support inodebits), then @@ -2371,7 +2385,7 @@ static int mds_intent_policy(struct ldlm_namespace *ns, getattr_part = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE; - rep->lock_policy_res2 = mds_getattr_lock(offset, req, + rep->lock_policy_res2 = mds_getattr_lock(req,DLM_INTENT_REC_OFF, getattr_part, &lockh); /* FIXME: LDLM can set req->rq_status. MDS sets policy_res{1,2} with disposition and status. diff --git a/lustre/mds/mds_internal.h b/lustre/mds/mds_internal.h index d90664a..cc7b49c 100644 --- a/lustre/mds/mds_internal.h +++ b/lustre/mds/mds_internal.h @@ -105,7 +105,7 @@ static inline void mds_inode_unset_orphan(struct inode *inode) req->rq_export->exp_mds_data.med_mcd; \ if (mcd->mcd_last_xid == req->rq_xid) { \ reconstruct; \ - RETURN(req->rq_repmsg->status); \ + RETURN(lustre_msg_get_status(req->rq_repmsg)); \ } \ DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")",\ mcd->mcd_last_xid); \ @@ -156,7 +156,7 @@ int mds_get_parents_children_locked(struct obd_device *obd, int child_mode); void mds_shrink_reply(struct obd_device *obd, struct ptlrpc_request *req, - struct mds_body *body); + struct mds_body *body, int md_off); int mds_get_cookie_size(struct obd_device *obd, struct lov_mds_md *lmm); /* mds/mds_lib.c */ int mds_update_unpack(struct ptlrpc_request *, int offset, @@ -205,7 +205,7 @@ int mds_open(struct mds_update_record *rec, int offset, struct ptlrpc_request *req, struct lustre_handle *); int mds_pin(struct ptlrpc_request *req, int offset); void mds_mfd_unlink(struct mds_file_data *mfd, int decref); -int mds_mfd_close(struct ptlrpc_request *req, int offset, struct obd_device *obd, +int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd, struct mds_file_data *mfd, int unlink_orphan); int mds_close(struct ptlrpc_request *req, int offset); int mds_done_writing(struct ptlrpc_request *req, int offset); diff --git a/lustre/mds/mds_join.c b/lustre/mds/mds_join.c index 184b965..9790280 100644 --- a/lustre/mds/mds_join.c +++ b/lustre/mds/mds_join.c @@ -347,8 +347,9 @@ int mds_join_file(struct mds_update_record *rec, struct ptlrpc_request *req, struct mds_rec_join *join_rec; ENTRY; - join_rec = lustre_swab_reqbuf (req, 5, sizeof (*join_rec), - lustre_swab_mds_rec_join); + join_rec = lustre_swab_reqbuf(req, DLM_INTENT_REC_OFF + 3, + sizeof(*join_rec), + lustre_swab_mds_rec_join); if (join_rec == NULL) RETURN (-EFAULT); diff --git a/lustre/mds/mds_lib.c b/lustre/mds/mds_lib.c index c136494..40e37b0 100644 --- a/lustre/mds/mds_lib.c +++ b/lustre/mds/mds_lib.c @@ -118,20 +118,19 @@ static int mds_setattr_unpack(struct ptlrpc_request *req, int offset, attr->ia_attr_flags = rec->sa_attr_flags; LASSERT_REQSWAB (req, offset + 1); - if (req->rq_reqmsg->bufcount > offset + 1) { - r->ur_eadata = lustre_msg_buf (req->rq_reqmsg, - offset + 1, 0); + if (lustre_msg_bufcount(req->rq_reqmsg) > offset + 1) { + r->ur_eadata = lustre_msg_buf(req->rq_reqmsg, offset + 1, 0); if (r->ur_eadata == NULL) - RETURN (-EFAULT); - r->ur_eadatalen = req->rq_reqmsg->buflens[offset + 1]; + RETURN(-EFAULT); + r->ur_eadatalen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); } - if (req->rq_reqmsg->bufcount > offset + 2) { + if (lustre_msg_bufcount(req->rq_reqmsg) > offset + 2) { r->ur_logcookies = lustre_msg_buf(req->rq_reqmsg, offset + 2,0); if (r->ur_eadata == NULL) RETURN (-EFAULT); - r->ur_cookielen = req->rq_reqmsg->buflens[offset + 2]; + r->ur_cookielen = lustre_msg_buflen(req->rq_reqmsg, offset + 2); } RETURN(0); @@ -143,8 +142,8 @@ static int mds_create_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_create *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_create); + rec = lustre_swab_reqbuf(req, offset, sizeof (*rec), + lustre_swab_mds_rec_create); if (rec == NULL) RETURN (-EFAULT); @@ -160,14 +159,14 @@ static int mds_create_unpack(struct ptlrpc_request *req, int offset, r->ur_time = rec->cr_time; r->ur_flags = rec->cr_flags; - LASSERT_REQSWAB (req, offset + 1); - r->ur_name = lustre_msg_string (req->rq_reqmsg, offset + 1, 0); + LASSERT_REQSWAB(req, offset + 1); + r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) RETURN (-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); - LASSERT_REQSWAB (req, offset + 2); - if (req->rq_reqmsg->bufcount > offset + 2) { + LASSERT_REQSWAB(req, offset + 2); + if (lustre_msg_bufcount(req->rq_reqmsg) > offset + 2) { /* NB for now, we only seem to pass NULL terminated symlink * target strings here. If this ever changes, we'll have * to stop checking for a buffer filled completely with a @@ -178,7 +177,7 @@ static int mds_create_unpack(struct ptlrpc_request *req, int offset, r->ur_tgt = lustre_msg_string(req->rq_reqmsg, offset + 2, 0); if (r->ur_tgt == NULL) RETURN (-EFAULT); - r->ur_tgtlen = req->rq_reqmsg->buflens[offset + 2]; + r->ur_tgtlen = lustre_msg_buflen(req->rq_reqmsg, offset + 2); } RETURN(0); } @@ -189,8 +188,8 @@ static int mds_link_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_link *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_link); + rec = lustre_swab_reqbuf(req, offset, sizeof (*rec), + lustre_swab_mds_rec_link); if (rec == NULL) RETURN (-EFAULT); @@ -203,11 +202,11 @@ static int mds_link_unpack(struct ptlrpc_request *req, int offset, r->ur_fid2 = &rec->lk_fid2; r->ur_time = rec->lk_time; - LASSERT_REQSWAB (req, offset + 1); - r->ur_name = lustre_msg_string (req->rq_reqmsg, offset + 1, 0); + LASSERT_REQSWAB(req, offset + 1); + r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) RETURN (-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); RETURN(0); } @@ -217,8 +216,8 @@ static int mds_unlink_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_unlink *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_unlink); + rec = lustre_swab_reqbuf(req, offset, sizeof (*rec), + lustre_swab_mds_rec_unlink); if (rec == NULL) RETURN(-EFAULT); @@ -232,11 +231,11 @@ static int mds_unlink_unpack(struct ptlrpc_request *req, int offset, r->ur_fid2 = &rec->ul_fid2; r->ur_time = rec->ul_time; - LASSERT_REQSWAB (req, offset + 1); + LASSERT_REQSWAB(req, offset + 1); r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) RETURN(-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); RETURN(0); } @@ -246,8 +245,8 @@ static int mds_rename_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_rename *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_rename); + rec = lustre_swab_reqbuf(req, offset, sizeof (*rec), + lustre_swab_mds_rec_rename); if (rec == NULL) RETURN(-EFAULT); @@ -264,13 +263,13 @@ static int mds_rename_unpack(struct ptlrpc_request *req, int offset, r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) RETURN(-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); LASSERT_REQSWAB (req, offset + 2); r->ur_tgt = lustre_msg_string(req->rq_reqmsg, offset + 2, 0); if (r->ur_tgt == NULL) RETURN(-EFAULT); - r->ur_tgtlen = req->rq_reqmsg->buflens[offset + 2]; + r->ur_tgtlen = lustre_msg_buflen(req->rq_reqmsg, offset + 2); RETURN(0); } @@ -280,10 +279,10 @@ static int mds_open_unpack(struct ptlrpc_request *req, int offset, struct mds_rec_create *rec; ENTRY; - rec = lustre_swab_reqbuf (req, offset, sizeof (*rec), - lustre_swab_mds_rec_create); + rec = lustre_swab_reqbuf(req, offset, sizeof(*rec), + lustre_swab_mds_rec_create); if (rec == NULL) - RETURN (-EFAULT); + RETURN(-EFAULT); r->ur_uc.luc_fsuid = rec->cr_fsuid; r->ur_uc.luc_fsgid = rec->cr_fsgid; @@ -297,18 +296,18 @@ static int mds_open_unpack(struct ptlrpc_request *req, int offset, r->ur_time = rec->cr_time; r->ur_flags = rec->cr_flags; - LASSERT_REQSWAB (req, offset + 1); - r->ur_name = lustre_msg_string (req->rq_reqmsg, offset + 1, 0); + LASSERT_REQSWAB(req, offset + 1); + r->ur_name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0); if (r->ur_name == NULL) - RETURN (-EFAULT); - r->ur_namelen = req->rq_reqmsg->buflens[offset + 1]; + RETURN(-EFAULT); + r->ur_namelen = lustre_msg_buflen(req->rq_reqmsg, offset + 1); - LASSERT_REQSWAB (req, offset + 2); - if (req->rq_reqmsg->bufcount > offset + 2) { + LASSERT_REQSWAB(req, offset + 2); + if (lustre_msg_bufcount(req->rq_reqmsg) > offset + 2) { r->ur_eadata = lustre_msg_buf(req->rq_reqmsg, offset + 2, 0); if (r->ur_eadata == NULL) RETURN (-EFAULT); - r->ur_eadatalen = req->rq_reqmsg->buflens[offset + 2]; + r->ur_eadatalen = lustre_msg_buflen(req->rq_reqmsg, offset + 2); } RETURN(0); } @@ -335,13 +334,13 @@ int mds_update_unpack(struct ptlrpc_request *req, int offset, /* NB don't lustre_swab_reqbuf() here. We're just taking a peek * and we want to leave it to the specific unpacker once we've * identified the message type */ - opcodep = lustre_msg_buf (req->rq_reqmsg, offset, sizeof (*opcodep)); + opcodep = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*opcodep)); if (opcodep == NULL) RETURN(-EFAULT); opcode = *opcodep; - if (lustre_msg_swabbed (req->rq_reqmsg)) - __swab32s (&opcode); + if (lustre_msg_swabbed(req->rq_reqmsg)) + __swab32s(&opcode); if (opcode >= REINT_MAX || mds_unpackers[opcode] == NULL) { CERROR("Unexpected opcode %d\n", opcode); diff --git a/lustre/mds/mds_lov.c b/lustre/mds/mds_lov.c index de55a9f..63ce99d 100644 --- a/lustre/mds/mds_lov.c +++ b/lustre/mds/mds_lov.c @@ -676,9 +676,10 @@ static int __mds_lov_synchronize(void *data) GOTO(out, rc); } + EXIT; out: class_decref(obd); - RETURN(rc); + return rc; } int mds_lov_synchronize(void *data) diff --git a/lustre/mds/mds_open.c b/lustre/mds/mds_open.c index f87d7cd..f35feff 100644 --- a/lustre/mds/mds_open.c +++ b/lustre/mds/mds_open.c @@ -263,7 +263,7 @@ static struct mds_file_data *mds_dentry_open(struct dentry *dentry, GOTO(cleanup_dentry, error = -ENOMEM); } - body = lustre_msg_buf(req->rq_repmsg, 1, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body)); if (flags & FMODE_WRITE) { /* FIXME: in recovery, need to pass old epoch here */ @@ -326,7 +326,7 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset, !(rec->ur_flags & FMODE_WRITE)) RETURN(0); - body = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body)); + body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body)); if (body->valid & OBD_MD_FLEASIZE) RETURN(0); @@ -360,11 +360,12 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset, mds_objids_from_lmm(*ids, lmm, &mds->mds_lov_desc); rc = fsfilt_set_md(obd, inode, *handle, lmm, lmm_size, "lov"); + if (rc) + CERROR("open replay failed to set md:%d\n", rc); lmm_buf = lustre_msg_buf(req->rq_repmsg, offset, lmm_size); LASSERT(lmm_buf); memcpy(lmm_buf, lmm, lmm_size); - if (rc) - CERROR("open replay failed to set md:%d\n", rc); + RETURN(rc); } @@ -510,9 +511,9 @@ static void reconstruct_open(struct mds_update_record *rec, int offset, int put_child = 1; ENTRY; - LASSERT(offset == 2); /* only called via intent */ - rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep)); - body = lustre_msg_buf(req->rq_repmsg, 1, sizeof (*body)); + LASSERT(offset == DLM_INTENT_REC_OFF); /* only called via intent */ + rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, sizeof(*rep)); + body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body)); /* copy rc, transno and disp; steal locks */ mds_req_from_mcd(req, mcd); @@ -545,8 +546,8 @@ static void reconstruct_open(struct mds_update_record *rec, int offset, mds_pack_inode2fid(&body->fid1, dchild->d_inode); mds_pack_inode2body(body, dchild->d_inode); if (S_ISREG(dchild->d_inode->i_mode)) { - rc = mds_pack_md(obd, req->rq_repmsg, 2, body, - dchild->d_inode, 1); + rc = mds_pack_md(obd, req->rq_repmsg, DLM_REPLY_REC_OFF + 1, + body, dchild->d_inode, 1); if (rc) LASSERT(rc == req->rq_status); @@ -558,11 +559,12 @@ static void reconstruct_open(struct mds_update_record *rec, int offset, } if (!(rec->ur_flags & MDS_OPEN_JOIN_FILE)) - lustre_shrink_reply(req, 2, body->eadatasize, 0); + lustre_shrink_reply(req, DLM_REPLY_REC_OFF + 1, + body->eadatasize, 0); if (req->rq_export->exp_connect_flags & OBD_CONNECT_ACL && !(rec->ur_flags & MDS_OPEN_JOIN_FILE)) { - int acl_off = body->eadatasize ? 3 : 2; + int acl_off = DLM_REPLY_REC_OFF + (body->eadatasize ? 2 : 1); rc = mds_pack_acl(med, dchild->d_inode, req->rq_repmsg, body, acl_off); @@ -678,8 +680,8 @@ static int mds_finish_open(struct ptlrpc_request *req, struct dentry *dchild, if (S_ISREG(dchild->d_inode->i_mode) && !(body->valid & OBD_MD_FLEASIZE)) { - rc = mds_pack_md(obd, req->rq_repmsg, 2, body, - dchild->d_inode, 0); + rc = mds_pack_md(obd, req->rq_repmsg, DLM_REPLY_REC_OFF + 1, + body, dchild->d_inode, 0); if (rc) { UNLOCK_INODE_MUTEX(dchild->d_inode); RETURN(rc); @@ -701,8 +703,8 @@ static int mds_finish_open(struct ptlrpc_request *req, struct dentry *dchild, if (!(body->valid & OBD_MD_FLEASIZE) && !(body->valid & OBD_MD_FLMODEASIZE)) { /* no EA: create objects */ - rc = mds_create_objects(req, 2, rec, mds, obd, - dchild, handle, &ids); + rc = mds_create_objects(req, DLM_REPLY_REC_OFF + 1, rec, + mds, obd, dchild, handle, &ids); if (rc) { CERROR("mds_create_objects: rc = %d\n", rc); UNLOCK_INODE_MUTEX(dchild->d_inode); @@ -719,11 +721,12 @@ static int mds_finish_open(struct ptlrpc_request *req, struct dentry *dchild, UNLOCK_INODE_MUTEX(dchild->d_inode); if (!(rec->ur_flags & MDS_OPEN_JOIN_FILE)) - lustre_shrink_reply(req, 2, body->eadatasize, 0); + lustre_shrink_reply(req, DLM_REPLY_REC_OFF + 1, + body->eadatasize, 0); if (req->rq_export->exp_connect_flags & OBD_CONNECT_ACL && !(rec->ur_flags & MDS_OPEN_JOIN_FILE)) { - int acl_off = body->eadatasize ? 3 : 2; + int acl_off = DLM_REPLY_REC_OFF + (body->eadatasize ? 2 : 1); rc = mds_pack_acl(&req->rq_export->exp_mds_data, dchild->d_inode, req->rq_repmsg, @@ -801,22 +804,22 @@ static int mds_open_by_fid(struct ptlrpc_request *req, struct ll_fid *fid, int mds_pin(struct ptlrpc_request *req, int offset) { struct obd_device *obd = req->rq_export->exp_obd; - struct mds_body *request_body, *reply_body; + struct mds_body *reqbody, *repbody; struct lvfs_run_ctxt saved; - int rc, size = sizeof(*reply_body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) }; ENTRY; - request_body = lustre_msg_buf(req->rq_reqmsg, offset, - sizeof(*request_body)); + reqbody = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*reqbody)); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - reply_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply_body)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); - rc = mds_open_by_fid(req, &request_body->fid1, reply_body, - request_body->flags, NULL, NULL); + rc = mds_open_by_fid(req, &reqbody->fid1, repbody, reqbody->flags, NULL, + NULL); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); RETURN(rc); @@ -864,16 +867,20 @@ int mds_open(struct mds_update_record *rec, int offset, int parent_mode = LCK_CR; void *handle = NULL; struct dentry_params dp; - unsigned int qcids[MAXQUOTAS] = {current->fsuid, current->fsgid}; - unsigned int qpids[MAXQUOTAS] = {0, 0}; + unsigned int qcids[MAXQUOTAS] = { current->fsuid, current->fsgid }; + unsigned int qpids[MAXQUOTAS] = { 0, 0 }; ENTRY; CLASSERT(MAXQUOTAS < 4); - if (offset == 2) { /* intent */ - rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep)); - body = lustre_msg_buf(req->rq_repmsg, 1, sizeof (*body)); - } else if (offset == MDS_REQ_REC_OFF) { /* non-intent reint */ - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + if (offset == DLM_INTENT_REC_OFF) { /* intent */ + rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, + sizeof(*rep)); + body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, + sizeof(*body)); + } else if (offset == REQ_REC_OFF) { /* non-intent reint */ + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); + LBUG(); /* XXX: not supported yet? */ } else { body = NULL; LBUG(); @@ -913,7 +920,8 @@ int mds_open(struct mds_update_record *rec, int offset, RETURN(-EFAULT); } - LASSERT(offset == 2); /* If we got here, we must be called via intent */ + /* If we got here, we must be called via intent */ + LASSERT(offset == DLM_INTENT_REC_OFF); med = &req->rq_export->exp_mds_data; if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK)) { @@ -1141,7 +1149,7 @@ found_child: if (rc) ldlm_lock_decref(&parent_lockh, parent_mode); else - ptlrpc_save_lock (req, &parent_lockh, parent_mode); + ptlrpc_save_lock(req, &parent_lockh, parent_mode); } /* trigger dqacq on the owner of child and parent */ @@ -1177,7 +1185,7 @@ int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd, request_body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*request_body)); if (req && req->rq_repmsg != NULL) - reply_body = lustre_msg_buf(req->rq_repmsg, 0, + reply_body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply_body)); fidlen = ll_fid2str(fidname, inode->i_ino, inode->i_generation); @@ -1231,7 +1239,7 @@ int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd, } if (req != NULL && req->rq_repmsg != NULL) { - lmm = lustre_msg_buf(req->rq_repmsg, 1, 0); + lmm = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF+1,0); stripe_count = le32_to_cpu(lmm->lmm_stripe_count); } @@ -1246,9 +1254,10 @@ int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd, if (req != NULL && req->rq_repmsg != NULL && (reply_body->valid & OBD_MD_FLEASIZE) && mds_log_op_unlink(obd, pending_child->d_inode, lmm, - req->rq_repmsg->buflens[1], - lustre_msg_buf(req->rq_repmsg, 2, 0), - req->rq_repmsg->buflens[2]) > 0) { + lustre_msg_buflen(req->rq_repmsg, REPLY_REC_OFF+1), + lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF+2, 0), + lustre_msg_buflen(req->rq_repmsg, REPLY_REC_OFF+2)) + > 0) { reply_body->valid |= OBD_MD_FLCOOKIE; } @@ -1350,12 +1359,13 @@ int mds_close(struct ptlrpc_request *req, int offset) struct mds_file_data *mfd; struct lvfs_run_ctxt saved; struct inode *inode; - int rc, repsize[3] = {sizeof(struct mds_body), - obd->u.mds.mds_max_mdsize, - obd->u.mds.mds_max_cookiesize}; + int rc, repsize[4] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_body), + obd->u.mds.mds_max_mdsize, + obd->u.mds.mds_max_cookiesize }; ENTRY; - rc = lustre_pack_reply(req, 3, repsize, NULL); + rc = lustre_pack_reply(req, 4, repsize, NULL); if (rc) { CERROR("lustre_pack_reply: rc = %d\n", rc); req->rq_status = rc; @@ -1397,19 +1407,21 @@ int mds_close(struct ptlrpc_request *req, int offset) /* child orphan sem protects orphan_dec_test && is_orphan race */ MDS_DOWN_WRITE_ORPHAN_SEM(inode); /* mds_mfd_close drops this */ if (mds_inode_is_orphan(inode) && mds_orphan_open_count(inode) == 1) { - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*body)); LASSERT(body != NULL); mds_pack_inode2fid(&body->fid1, inode); mds_pack_inode2body(body, inode); - mds_pack_md(obd, req->rq_repmsg, 1,body,inode,MDS_PACK_MD_LOCK); + mds_pack_md(obd, req->rq_repmsg, REPLY_REC_OFF + 1, body, inode, + MDS_PACK_MD_LOCK); } push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); req->rq_status = mds_mfd_close(req, offset, obd, mfd, 1); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); - mds_shrink_reply(obd, req, body); + mds_shrink_reply(obd, req, body, REPLY_REC_OFF + 1); if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK)) { CERROR("test case OBD_FAIL_MDS_CLOSE_PACK\n"); req->rq_status = -ENOMEM; @@ -1422,7 +1434,8 @@ int mds_close(struct ptlrpc_request *req, int offset) int mds_done_writing(struct ptlrpc_request *req, int offset) { struct mds_body *body; - int rc, size = sizeof(struct mds_body); + int rc, size[2] = { sizeof(struct ptlrpc_body), + sizeof(struct mds_body) }; ENTRY; MDS_CHECK_RESENT(req, mds_reconstruct_generic(req)); @@ -1435,7 +1448,7 @@ int mds_done_writing(struct ptlrpc_request *req, int offset) RETURN(-EFAULT); } - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) { CERROR("lustre_pack_reply: rc = %d\n", rc); req->rq_status = rc; diff --git a/lustre/mds/mds_reint.c b/lustre/mds/mds_reint.c index d13d7ea..79dc8a5 100644 --- a/lustre/mds/mds_reint.c +++ b/lustre/mds/mds_reint.c @@ -141,7 +141,7 @@ int mds_finish_transno(struct mds_obd *mds, struct inode *inode, void *handle, off = med->med_lr_off; - transno = req->rq_reqmsg->transno; + transno = lustre_msg_get_transno(req->rq_reqmsg); if (rc != 0) { if (transno != 0) { CERROR("%s: replay %s transno "LPU64" failed: rc %d\n", @@ -160,7 +160,8 @@ int mds_finish_transno(struct mds_obd *mds, struct inode *inode, void *handle, mds->mds_last_transno = transno; spin_unlock(&mds->mds_transno_lock); } - req->rq_repmsg->transno = req->rq_transno = transno; + req->rq_transno = transno; + lustre_msg_set_transno(req->rq_repmsg, transno); mcd->mcd_last_transno = cpu_to_le64(transno); mcd->mcd_last_xid = cpu_to_le64(req->rq_xid); mcd->mcd_last_result = cpu_to_le32(rc); @@ -318,10 +319,12 @@ void mds_steal_ack_locks(struct ptlrpc_request *req) if (oldrep->rs_xid != req->rq_xid) continue; - if (oldrep->rs_msg.opc != req->rq_reqmsg->opc) + if (lustre_msg_get_opc(oldrep->rs_msg) != + lustre_msg_get_opc(req->rq_reqmsg)) CERROR ("Resent req xid "LPX64" has mismatched opc: " "new %d old %d\n", req->rq_xid, - req->rq_reqmsg->opc, oldrep->rs_msg.opc); + lustre_msg_get_opc(req->rq_reqmsg), + lustre_msg_get_opc(oldrep->rs_msg)); svc = oldrep->rs_service; spin_lock (&svc->srv_lock); @@ -331,7 +334,8 @@ void mds_steal_ack_locks(struct ptlrpc_request *req) CWARN("Stealing %d locks from rs %p x"LPD64".t"LPD64 " o%d NID %s\n", oldrep->rs_nlocks, oldrep, - oldrep->rs_xid, oldrep->rs_transno, oldrep->rs_msg.opc, + oldrep->rs_xid, oldrep->rs_transno, + lustre_msg_get_opc(oldrep->rs_msg), libcfs_nid2str(exp->exp_connection->c_peer.nid)); for (i = 0; i < oldrep->rs_nlocks; i++) @@ -353,8 +357,10 @@ void mds_req_from_mcd(struct ptlrpc_request *req, struct mds_client_data *mcd) { DEBUG_REQ(D_HA, req, "restoring transno "LPD64"/status %d", mcd->mcd_last_transno, mcd->mcd_last_result); - req->rq_repmsg->transno = req->rq_transno = mcd->mcd_last_transno; - req->rq_repmsg->status = req->rq_status = mcd->mcd_last_result; + req->rq_transno = mcd->mcd_last_transno; + lustre_msg_set_transno(req->rq_repmsg, req->rq_transno); + req->rq_status = mcd->mcd_last_result; + lustre_msg_set_status(req->rq_repmsg, req->rq_status); mds_steal_ack_locks(req); } @@ -375,7 +381,7 @@ static void reconstruct_reint_setattr(struct mds_update_record *rec, return; } - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body)); mds_pack_inode2fid(&body->fid1, de->d_inode); mds_pack_inode2body(body, de->d_inode); @@ -472,12 +478,13 @@ static int mds_reint_setattr(struct mds_update_record *rec, int offset, struct llog_cookie *logcookies = NULL; int lmm_size = 0, need_lock = 1, cookie_size = 0; int rc = 0, cleanup_phase = 0, err, locked = 0; - unsigned int qcids[MAXQUOTAS] = {0, 0}; - unsigned int qpids[MAXQUOTAS] = {rec->ur_iattr.ia_uid, - rec->ur_iattr.ia_gid}; + unsigned int qcids[MAXQUOTAS] = { 0, 0 }; + unsigned int qpids[MAXQUOTAS] = { rec->ur_iattr.ia_uid, + rec->ur_iattr.ia_gid }; ENTRY; - LASSERT(offset == MDS_REQ_REC_OFF); + LASSERT(offset == REQ_REC_OFF); + offset = REPLY_REC_OFF; DEBUG_REQ(D_INODE, req, "setattr "LPU64"/%u %x", rec->ur_fid1->id, rec->ur_fid1->generation, rec->ur_iattr.ia_valid); @@ -606,7 +613,7 @@ static int mds_reint_setattr(struct mds_update_record *rec, int offset, } } - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body)); mds_pack_inode2fid(&body->fid1, inode); mds_pack_inode2body(body, inode); @@ -699,9 +706,11 @@ static void reconstruct_reint_create(struct mds_update_record *rec, int offset, LASSERT(!IS_ERR(parent)); child = ll_lookup_one_len(rec->ur_name, parent, rec->ur_namelen - 1); LASSERT(!IS_ERR(child)); - body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*body)); + + body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body)); mds_pack_inode2fid(&body->fid1, child->d_inode); mds_pack_inode2body(body, child->d_inode); + l_dput(parent); l_dput(child); } @@ -719,12 +728,14 @@ static int mds_reint_create(struct mds_update_record *rec, int offset, struct lustre_handle lockh; int rc = 0, err, type = rec->ur_mode & S_IFMT, cleanup_phase = 0; int created = 0; - unsigned int qcids[MAXQUOTAS] = {current->fsuid, current->fsgid}; - unsigned int qpids[MAXQUOTAS] = {0, 0}; + unsigned int qcids[MAXQUOTAS] = { current->fsuid, current->fsgid }; + unsigned int qpids[MAXQUOTAS] = { 0, 0 }; struct dentry_params dp; ENTRY; - LASSERT(offset == MDS_REQ_REC_OFF); + LASSERT(offset == REQ_REC_OFF); + offset = REPLY_REC_OFF; + LASSERT(!strcmp(req->rq_export->exp_obd->obd_type->typ_name, LUSTRE_MDS_NAME)); @@ -883,7 +894,7 @@ static int mds_reint_create(struct mds_update_record *rec, int offset, rc); } - body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body)); mds_pack_inode2fid(&body->fid1, inode); mds_pack_inode2body(body, inode); } @@ -1451,7 +1462,7 @@ int mds_get_cookie_size(struct obd_device *obd, struct lov_mds_md *lmm) } void mds_shrink_reply(struct obd_device *obd, struct ptlrpc_request *req, - struct mds_body *body) + struct mds_body *body, int md_off) { int cookie_size = 0, md_size = 0; @@ -1461,15 +1472,15 @@ void mds_shrink_reply(struct obd_device *obd, struct ptlrpc_request *req, if (body && body->valid & OBD_MD_FLCOOKIE) { LASSERT(body->valid & OBD_MD_FLEASIZE); cookie_size = mds_get_cookie_size(obd, lustre_msg_buf( - req->rq_repmsg, 1, 0)); + req->rq_repmsg, md_off, 0)); } CDEBUG(D_INFO, "Shrink to md_size %d cookie_size %d \n", md_size, cookie_size); - lustre_shrink_reply(req, 1, md_size, 1); + lustre_shrink_reply(req, md_off, md_size, 1); - lustre_shrink_reply(req, md_size? 2:1, cookie_size, 0); + lustre_shrink_reply(req, md_off + (md_size > 0), cookie_size, 0); } static int mds_reint_unlink(struct mds_update_record *rec, int offset, @@ -1484,11 +1495,12 @@ static int mds_reint_unlink(struct mds_update_record *rec, int offset, struct lustre_handle parent_lockh, child_lockh, child_reuse_lockh; void *handle = NULL; int rc = 0, cleanup_phase = 0; - unsigned int qcids [MAXQUOTAS] = {0, 0}; - unsigned int qpids [MAXQUOTAS] = {0, 0}; + unsigned int qcids[MAXQUOTAS] = { 0, 0 }; + unsigned int qpids[MAXQUOTAS] = { 0, 0 }; ENTRY; - LASSERT(offset == MDS_REQ_REC_OFF || offset == 2); + LASSERT(offset == REQ_REC_OFF); /* || offset == DLM_INTENT_REC_OFF); */ + offset = REPLY_REC_OFF; DEBUG_REQ(D_INODE, req, "parent ino "LPU64"/%u, child %s", rec->ur_fid1->id, rec->ur_fid1->generation, rec->ur_name); @@ -1551,10 +1563,10 @@ static int mds_reint_unlink(struct mds_update_record *rec, int offset, OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_UNLINK_WRITE, dparent->d_inode->i_sb); /* ldlm_reply in buf[0] if called via intent */ - if (offset) - offset = 1; + if (offset == DLM_INTENT_REC_OFF) + offset = DLM_REPLY_REC_OFF; - body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body)); LASSERT(body != NULL); /* child orphan sem protects orphan_dec_test && is_orphan race */ @@ -1635,9 +1647,10 @@ static int mds_reint_unlink(struct mds_update_record *rec, int offset, OBD_MD_FLATIME | OBD_MD_FLMTIME); } else if (mds_log_op_unlink(obd, child_inode, lustre_msg_buf(req->rq_repmsg, offset + 1, 0), - req->rq_repmsg->buflens[offset + 1], + lustre_msg_buflen(req->rq_repmsg, offset + 1), lustre_msg_buf(req->rq_repmsg, offset + 2, 0), - req->rq_repmsg->buflens[offset+2]) > 0){ + lustre_msg_buflen(req->rq_repmsg, offset+2)) > + 0) { body->valid |= OBD_MD_FLCOOKIE; } } @@ -1694,7 +1707,7 @@ cleanup: } req->rq_status = rc; - mds_shrink_reply(obd, req, body); + mds_shrink_reply(obd, req, body, REPLY_REC_OFF + 1); /* trigger dqrel on the owner of child and parent */ lquota_adjust(quota_interface, obd, qcids, qpids, rc, FSFILT_OP_UNLINK); @@ -1719,7 +1732,7 @@ static int mds_reint_link(struct mds_update_record *rec, int offset, int rc = 0, cleanup_phase = 0; ENTRY; - LASSERT(offset == MDS_REQ_REC_OFF); + LASSERT(offset == REQ_REC_OFF); DEBUG_REQ(D_INODE, req, "original "LPU64"/%u to "LPU64"/%u %s", rec->ur_fid1->id, rec->ur_fid1->generation, @@ -2057,11 +2070,12 @@ static int mds_reint_rename(struct mds_update_record *rec, int offset, struct lov_mds_md *lmm = NULL; int rc = 0, lock_count = 3, cleanup_phase = 0; void *handle = NULL; - unsigned int qcids[MAXQUOTAS] = {0, 0}; - unsigned int qpids[4] = {0, 0, 0, 0}; + unsigned int qcids[MAXQUOTAS] = { 0, 0 }; + unsigned int qpids[4] = { 0, 0, 0, 0 }; ENTRY; - LASSERT(offset == MDS_REQ_REC_OFF); + LASSERT(offset == REQ_REC_OFF); + offset = REPLY_REC_OFF; DEBUG_REQ(D_INODE, req, "parent "LPU64"/%u %s to "LPU64"/%u %s", rec->ur_fid1->id, rec->ur_fid1->generation, rec->ur_name, @@ -2118,7 +2132,7 @@ static int mds_reint_rename(struct mds_update_record *rec, int offset, /* if we are about to remove the target at first, pass the EA of * that inode to client to perform and cleanup on OST */ - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body)); LASSERT(body != NULL); /* child orphan sem protects orphan_dec_test && is_orphan race */ @@ -2134,8 +2148,8 @@ static int mds_reint_rename(struct mds_update_record *rec, int offset, } else if (S_ISREG(new_inode->i_mode)) { mds_pack_inode2fid(&body->fid1, new_inode); mds_pack_inode2body(body, new_inode); - mds_pack_md(obd, req->rq_repmsg, 1, body, new_inode, - MDS_PACK_MD_LOCK); + mds_pack_md(obd, req->rq_repmsg, offset + 1, body, + new_inode, MDS_PACK_MD_LOCK); } } @@ -2150,7 +2164,7 @@ no_unlink: GOTO(cleanup, rc = -EINVAL); #endif - lmm = lustre_msg_buf(req->rq_repmsg, 1, 0); + lmm = lustre_msg_buf(req->rq_repmsg, offset + 1, 0); handle = fsfilt_start_log(obd, de_tgtdir->d_inode, FSFILT_OP_RENAME, NULL, le32_to_cpu(lmm->lmm_stripe_count)); @@ -2178,10 +2192,15 @@ no_unlink: body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLATIME | OBD_MD_FLMTIME); } else if (mds_log_op_unlink(obd, new_inode, - lustre_msg_buf(req->rq_repmsg,1,0), - req->rq_repmsg->buflens[1], - lustre_msg_buf(req->rq_repmsg,2,0), - req->rq_repmsg->buflens[2]) > 0) { + lustre_msg_buf(req->rq_repmsg, + offset + 1, 0), + lustre_msg_buflen(req->rq_repmsg, + offset + 1), + lustre_msg_buf(req->rq_repmsg, + offset + 2, 0), + lustre_msg_buflen(req->rq_repmsg, + offset + 2)) + > 0) { body->valid |= OBD_MD_FLCOOKIE; } } diff --git a/lustre/mds/mds_xattr.c b/lustre/mds/mds_xattr.c index e9a4825..16ee83f65 100644 --- a/lustre/mds/mds_xattr.c +++ b/lustre/mds/mds_xattr.c @@ -52,15 +52,15 @@ static int mds_getxattr_pack_msg(struct ptlrpc_request *req, struct mds_body *body) { struct inode *inode = de->d_inode; - int size[2] = {sizeof(*body)}, bufcnt = 1; char *xattr_name; - int rc = -EOPNOTSUPP, rc2; + int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int bufcnt = 2, rc = -EOPNOTSUPP, rc2; if (inode == NULL) return -ENOENT; if (body->valid & OBD_MD_FLXATTR) { - xattr_name = lustre_msg_string(req->rq_reqmsg, 1, 0); + xattr_name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF+1,0); if (!xattr_name) { CERROR("can't extract xattr name\n"); return -EFAULT; @@ -84,7 +84,7 @@ static int mds_getxattr_pack_msg(struct ptlrpc_request *req, if (rc != -ENODATA && rc != -EOPNOTSUPP) CWARN("get inode %lu EA size error: %d\n", inode->i_ino, rc); - bufcnt = 0; + bufcnt = 1; } else { size[bufcnt++] = min_t(int, body->eadatasize, rc); } @@ -119,15 +119,16 @@ static int mds_getxattr_internal(struct obd_device *obd, if (inode == NULL) GOTO(out, rc = -ENOENT); - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); LASSERT(repbody != NULL); - buflen = lustre_msg_buflen(req->rq_repmsg, 1); + buflen = lustre_msg_buflen(req->rq_repmsg, REPLY_REC_OFF + 1); if (buflen) - buf = lustre_msg_buf(req->rq_repmsg, 1, buflen); + buf = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, buflen); if (reqbody->valid & OBD_MD_FLXATTR) { - xattr_name = lustre_msg_string(req->rq_reqmsg, 1, 0); + xattr_name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF+1,0); DEBUG_REQ(D_INODE, req, "getxattr %s\n", xattr_name); if (inode->i_op && inode->i_op->getxattr) { @@ -169,15 +170,16 @@ int mds_getxattr(struct ptlrpc_request *req) struct lvfs_run_ctxt saved; struct dentry *de; struct mds_body *body; - struct lvfs_ucred uc = {NULL,}; + struct lvfs_ucred uc = { NULL, }; int rc = 0; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_mds_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_mds_body); if (body == NULL) RETURN(-EFAULT); - rc = mds_init_ucred(&uc, req, 0); + rc = mds_init_ucred(&uc, req, REQ_REC_OFF); if (rc) GOTO(out_ucred, rc); @@ -223,7 +225,6 @@ int mds_setxattr_internal(struct ptlrpc_request *req, struct mds_body *body) __u64 lockpart; ENTRY; - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); LASSERT(body); DEBUG_REQ(D_INODE, req, "setxattr "LPU64"/%u", @@ -234,7 +235,7 @@ int mds_setxattr_internal(struct ptlrpc_request *req, struct mds_body *body) lockpart = MDS_INODELOCK_UPDATE; /* various sanity check for xattr name */ - xattr_name = lustre_msg_string(req->rq_reqmsg, 1, 0); + xattr_name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1, 0); if (!xattr_name) { CERROR("can't extract xattr name\n"); GOTO(out, rc = -EPROTO); @@ -274,15 +275,16 @@ int mds_setxattr_internal(struct ptlrpc_request *req, struct mds_body *body) if (body->valid & OBD_MD_FLXATTR) { if (inode->i_op && inode->i_op->setxattr) { - if (req->rq_reqmsg->bufcount < 3) { + if (lustre_msg_bufcount(req->rq_reqmsg) < 4) { CERROR("no xattr data supplied\n"); GOTO(out_trans, rc = -EFAULT); } - xattrlen = lustre_msg_buflen(req->rq_reqmsg, 2); + xattrlen = lustre_msg_buflen(req->rq_reqmsg, + REQ_REC_OFF + 2); if (xattrlen) - xattr = lustre_msg_buf(req->rq_reqmsg, 2, - xattrlen); + xattr = lustre_msg_buf(req->rq_reqmsg, + REQ_REC_OFF+2, xattrlen); LOCK_INODE_MUTEX(inode); lock_24kernel(); @@ -328,24 +330,25 @@ int mds_setxattr(struct ptlrpc_request *req) struct obd_device *obd = req->rq_export->exp_obd; struct lvfs_run_ctxt saved; struct mds_body *body; - struct lvfs_ucred uc = {NULL,}; + struct lvfs_ucred uc = { NULL, }; int rc; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_mds_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_mds_body); if (body == NULL) RETURN(-EFAULT); - if (req->rq_reqmsg->bufcount < 2) + if (lustre_msg_bufcount(req->rq_reqmsg) < 3) RETURN(-EFAULT); - rc = mds_init_ucred(&uc, req, 0); + rc = mds_init_ucred(&uc, req, REQ_REC_OFF); if (rc) GOTO(out_ucred, rc); push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc); - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) GOTO(out_pop, rc); diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index 0df5446..0de5386 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -636,28 +636,29 @@ static int mgc_target_register(struct obd_export *exp, { struct ptlrpc_request *req; struct mgs_target_info *req_mti, *rep_mti; - int size = sizeof(*req_mti); - int rep_size = sizeof(*mti); + int size[] = { sizeof(struct ptlrpc_body), sizeof(*req_mti) }; + int rep_size[] = { sizeof(struct ptlrpc_body), sizeof(*mti) }; int rc; ENTRY; req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MGS_VERSION, - MGS_TARGET_REG, 1, &size, NULL); + MGS_TARGET_REG, 2, size, NULL); if (!req) RETURN(-ENOMEM); - req_mti = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*req_mti)); + req_mti = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*req_mti)); if (!req_mti) RETURN(-ENOMEM); memcpy(req_mti, mti, sizeof(*req_mti)); - req->rq_replen = lustre_msg_size(1, &rep_size); + ptlrpc_req_set_repsize(req, 2, rep_size); CDEBUG(D_MGC, "register %s\n", mti->mti_svname); rc = ptlrpc_queue_wait(req); if (!rc) { - rep_mti = lustre_swab_repbuf(req, 0, sizeof(*rep_mti), + rep_mti = lustre_swab_repbuf(req, REPLY_REC_OFF, + sizeof(*rep_mti), lustre_swab_mgs_target_info); memcpy(mti, rep_mti, sizeof(*rep_mti)); CDEBUG(D_MGC, "register %s got index = %d\n", diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 87d6ded..cabffd2 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -351,11 +351,11 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req) struct obd_device *obd = req->rq_export->exp_obd; struct lustre_handle lockh; struct mgs_target_info *mti, *rep_mti; - int rep_size = sizeof(*mti); + int rep_size[] = { sizeof(struct ptlrpc_body), sizeof(*mti) }; int rc = 0, lockrc; ENTRY; - mti = lustre_swab_reqbuf(req, 0, sizeof(*mti), + mti = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*mti), lustre_swab_mgs_target_info); if (!(mti->mti_flags & (LDD_F_WRITECONF | LDD_F_UPGRADE14 | @@ -434,9 +434,10 @@ out: out_nolock: CDEBUG(D_MGS, "replying with %s, index=%d, rc=%d\n", mti->mti_svname, mti->mti_stripe_index, rc); - lustre_pack_reply(req, 1, &rep_size, NULL); + lustre_pack_reply(req, 2, rep_size, NULL); /* send back the whole mti in the reply */ - rep_mti = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep_mti)); + rep_mti = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*rep_mti)); memcpy(rep_mti, mti, sizeof(*rep_mti)); RETURN(rc); } @@ -444,26 +445,27 @@ out_nolock: int mgs_handle(struct ptlrpc_request *req) { int fail = OBD_FAIL_MGS_ALL_REPLY_NET; - int rc = 0; + int opc, rc = 0; ENTRY; OBD_FAIL_RETURN(OBD_FAIL_MGS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0); LASSERT(current->journal_info == NULL); - if (req->rq_reqmsg->opc != MGS_CONNECT) { + opc = lustre_msg_get_opc(req->rq_reqmsg); + if (opc != MGS_CONNECT) { if (req->rq_export == NULL) { CERROR("lustre_mgs: operation %d on unconnected MGS\n", - req->rq_reqmsg->opc); + opc); req->rq_status = -ENOTCONN; GOTO(out, rc = -ENOTCONN); } } - switch (req->rq_reqmsg->opc) { + switch (opc) { case MGS_CONNECT: DEBUG_REQ(D_MGS, req, "connect"); rc = target_handle_connect(req, mgs_handle); - if (!rc && (req->rq_reqmsg->conn_cnt > 1)) + if (!rc && (lustre_msg_get_conn_cnt(req->rq_reqmsg) > 1)) /* Make clients trying to reconnect after a MGS restart happy; also requires obd_replayable */ lustre_msg_add_op_flags(req->rq_repmsg, @@ -533,8 +535,7 @@ int mgs_handle(struct ptlrpc_request *req) LASSERT(current->journal_info == NULL); - CDEBUG(D_CONFIG | (rc?D_ERROR:0), "MGS handle cmd=%d rc=%d\n", - req->rq_reqmsg->opc, rc); + CDEBUG(D_CONFIG | (rc?D_ERROR:0), "MGS handle cmd=%d rc=%d\n", opc, rc); out: target_send_reply(req, rc, fail); diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 7ed2f36..5279bcd 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -648,6 +648,10 @@ struct obd_import *class_new_import(struct obd_device *obd) CFS_INIT_LIST_HEAD(&imp->imp_handle.h_link); class_handle_hash(&imp->imp_handle, import_handle_addref); + /* the default magic is V1, will be used in connect RPC, and + * then adjusted according to the flags in request/reply. */ + imp->imp_msg_magic = LUSTRE_MSG_MAGIC_V1; + return imp; } EXPORT_SYMBOL(class_new_import); diff --git a/lustre/obdclass/llog_lvfs.c b/lustre/obdclass/llog_lvfs.c index 2eedc32..13cf2ac 100644 --- a/lustre/obdclass/llog_lvfs.c +++ b/lustre/obdclass/llog_lvfs.c @@ -708,9 +708,10 @@ int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd, int rc; int size = sizeof(*idarray) * count; loff_t off = 0; + ENTRY; if (!count) - return (0); + RETURN(0); push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700); @@ -736,11 +737,12 @@ int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd, GOTO(out, rc); } + EXIT; out: pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); if (file && !IS_ERR(file)) rc = filp_close(file, 0); - RETURN(rc); + return rc; } EXPORT_SYMBOL(llog_get_cat_list); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index b21314c..44c6a87 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -1307,7 +1307,8 @@ static void server_wait_finished(struct vfsmount *mnt) l_wait_event(waitq, 0, &lwi); } if (atomic_read(&mnt->mnt_count)) { - CERROR("Mount is still busy, giving up.\n"); + CERROR("Mount %p is still busy(%d refs), giving up.\n", + mnt, atomic_read(&mnt->mnt_count)); } } diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 7f6ebb5..e3aea4b 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -1128,22 +1128,25 @@ static int filter_intent_policy(struct ldlm_namespace *ns, struct ldlm_reply *rep; struct list_head *tmp; ldlm_error_t err; - int tmpflags = 0, rc, repsize[2] = {sizeof(*rep), sizeof(*reply_lvb)}; - int only_liblustre = 0; + int rc, tmpflags = 0, only_liblustre = 0; + int repsize[3] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREPLY_OFF] = sizeof(*rep), + [DLM_REPLY_REC_OFF] = sizeof(*reply_lvb) }; ENTRY; policy = ldlm_get_processing_policy(res); LASSERT(policy != NULL); LASSERT(req != NULL); - rc = lustre_pack_reply(req, 2, repsize, NULL); + rc = lustre_pack_reply(req, 3, repsize, NULL); if (rc) RETURN(req->rq_status = rc); - rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep)); + rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, sizeof(*rep)); LASSERT(rep != NULL); - reply_lvb = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*reply_lvb)); + reply_lvb = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, + sizeof(*reply_lvb)); LASSERT(reply_lvb != NULL); //fixup_handle_for_resent_req(req, lock, &lockh); diff --git a/lustre/osc/osc_create.c b/lustre/osc/osc_create.c index d21c3e8..2abbc7f 100644 --- a/lustre/osc/osc_create.c +++ b/lustre/osc/osc_create.c @@ -55,7 +55,7 @@ static int osc_interpret_create(struct ptlrpc_request *req, void *data, int rc) ENTRY; if (req->rq_repmsg) { - body = lustre_swab_repbuf(req, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_ost_body); if (body == NULL && rc == 0) rc = -EPROTO; @@ -80,7 +80,8 @@ static int osc_interpret_create(struct ptlrpc_request *req, void *data, int rc) spin_unlock(&oscc->oscc_lock); DEBUG_REQ(D_ERROR, req, "unknown rc %d from async create: failing oscc", rc); - ptlrpc_fail_import(req->rq_import, req->rq_reqmsg->conn_cnt); + ptlrpc_fail_import(req->rq_import, + lustre_msg_get_conn_cnt(req->rq_reqmsg)); } else { if (rc == 0) { oscc->oscc_flags &= ~OSCC_FLAG_LOW; @@ -106,7 +107,7 @@ static int oscc_internal_create(struct osc_creator *oscc) { struct ptlrpc_request *request; struct ost_body *body; - int size = sizeof(*body); + int size[] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; spin_lock(&oscc->oscc_lock); @@ -130,8 +131,8 @@ static int oscc_internal_create(struct osc_creator *oscc) spin_unlock(&oscc->oscc_lock); request = ptlrpc_prep_req(oscc->oscc_obd->u.cli.cl_import, - LUSTRE_OST_VERSION, OST_CREATE, 1, - &size, NULL); + LUSTRE_OST_VERSION, OST_CREATE, 2, + size, NULL); if (request == NULL) { spin_lock(&oscc->oscc_lock); oscc->oscc_flags &= ~OSCC_FLAG_CREATING; @@ -140,7 +141,7 @@ static int oscc_internal_create(struct osc_creator *oscc) } request->rq_request_portal = OST_CREATE_PORTAL; //XXX FIXME bug 249 - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*body)); + body = lustre_msg_buf(request->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); spin_lock(&oscc->oscc_lock); body->oa.o_id = oscc->oscc_last_id + oscc->oscc_grow_count; @@ -149,7 +150,7 @@ static int oscc_internal_create(struct osc_creator *oscc) CDEBUG(D_HA, "preallocating through id "LPU64" (last used "LPU64")\n", body->oa.o_id, oscc->oscc_next_id); - request->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(request, 2, size); request->rq_async_args.pointer_arg[0] = oscc; request->rq_interpret_reply = osc_interpret_create; diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index c508bd8..328cf70 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -149,7 +149,8 @@ static int osc_getattr_interpret(struct ptlrpc_request *req, if (rc != 0) RETURN(rc); - body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body) { CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode); memcpy(aa->aa_oa, &body->oa, sizeof(*aa->aa_oa)); @@ -170,56 +171,56 @@ static int osc_getattr_async(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *md, struct ptlrpc_request_set *set) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; struct ost_body *body; - int size = sizeof(*body); + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; struct osc_getattr_async_args *aa; ENTRY; - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_GETATTR, 1, &size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_GETATTR, 2, size,NULL); + if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); memcpy(&body->oa, oa, sizeof(*oa)); - request->rq_replen = lustre_msg_size(1, &size); - request->rq_interpret_reply = osc_getattr_interpret; + ptlrpc_req_set_repsize(req, 2, size); + req->rq_interpret_reply = osc_getattr_interpret; - LASSERT (sizeof (*aa) <= sizeof (request->rq_async_args)); - aa = (struct osc_getattr_async_args *)&request->rq_async_args; + LASSERT (sizeof (*aa) <= sizeof (req->rq_async_args)); + aa = (struct osc_getattr_async_args *)&req->rq_async_args; aa->aa_oa = oa; - ptlrpc_set_add_req (set, request); + ptlrpc_set_add_req(set, req); RETURN (0); } static int osc_getattr(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *md) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; struct ost_body *body; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_GETATTR, 1, &size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_GETATTR, 2, size, NULL); + if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); memcpy(&body->oa, oa, sizeof(*oa)); - request->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc) { CERROR("%s failed: rc = %d\n", __FUNCTION__, rc); GOTO(out, rc); } - body = lustre_swab_repbuf(request, 0, sizeof (*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_ost_body); if (body == NULL) { CERROR ("can't unpack ost_body\n"); @@ -235,33 +236,33 @@ static int osc_getattr(struct obd_export *exp, struct obdo *oa, EXIT; out: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); return rc; } static int osc_setattr(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *md, struct obd_trans_info *oti) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; struct ost_body *body; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_SETATTR, 1, &size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_SETATTR, 2, size, NULL); + if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); memcpy(&body->oa, oa, sizeof(*oa)); - request->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - body = lustre_swab_repbuf(request, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_ost_body); if (body == NULL) GOTO(out, rc = -EPROTO); @@ -270,7 +271,7 @@ static int osc_setattr(struct obd_export *exp, struct obdo *oa, EXIT; out: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); RETURN(0); } @@ -278,28 +279,28 @@ static int osc_setattr_async(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *md, struct obd_trans_info *oti) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; struct ost_body *body; - int rc = 0, size = sizeof(*body); + int rc = 0, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; LASSERT(oti); - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_SETATTR, 1, &size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_SETATTR, 2, size, NULL); + if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); if (oa->o_valid & OBD_MD_FLCOOKIE) memcpy(obdo_logcookie(oa), oti->oti_logcookies, sizeof(*oti->oti_logcookies)); memcpy(&body->oa, oa, sizeof(*oa)); - request->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); /* do mds to ost setattr asynchronouly */ - ptlrpcd_add_req(request); + ptlrpcd_add_req(req); RETURN(rc); } @@ -307,10 +308,10 @@ static int osc_setattr_async(struct obd_export *exp, struct obdo *oa, int osc_real_create(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md **ea, struct obd_trans_info *oti) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; struct ost_body *body; struct lov_stripe_md *lsm; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; LASSERT(oa); @@ -323,29 +324,29 @@ int osc_real_create(struct obd_export *exp, struct obdo *oa, RETURN(rc); } - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_CREATE, 1, &size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_CREATE, 2, size, NULL); + if (!req) GOTO(out, rc = -ENOMEM); - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); memcpy(&body->oa, oa, sizeof(body->oa)); - request->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); if (oa->o_valid & OBD_MD_FLINLINE) { LASSERT((oa->o_valid & OBD_MD_FLFLAGS) && oa->o_flags == OBD_FL_DELORPHAN); - DEBUG_REQ(D_HA, request, + DEBUG_REQ(D_HA, req, "delorphan from OST integration"); - /* Don't resend the delorphan request */ - request->rq_no_resend = request->rq_no_delay = 1; + /* Don't resend the delorphan req */ + req->rq_no_resend = req->rq_no_delay = 1; } - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc) GOTO(out_req, rc); - body = lustre_swab_repbuf(request, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_ost_body); if (body == NULL) { CERROR ("can't unpack ost_body\n"); @@ -366,7 +367,7 @@ int osc_real_create(struct obd_export *exp, struct obdo *oa, *ea = lsm; if (oti != NULL) { - oti->oti_transno = request->rq_repmsg->transno; + oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg); if (oa->o_valid & OBD_MD_FLCOOKIE) { if (!oti->oti_logcookies) @@ -376,10 +377,11 @@ int osc_real_create(struct obd_export *exp, struct obdo *oa, } } - CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno); + CDEBUG(D_HA, "transno: "LPD64"\n", + lustre_msg_get_transno(req->rq_repmsg)); EXIT; out_req: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); out: if (rc && !*ea) obd_free_memmd(exp, &lsm); @@ -390,9 +392,9 @@ static int osc_punch(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *md, obd_size start, obd_size end, struct obd_trans_info *oti) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; struct ost_body *body; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; if (!oa) { @@ -400,12 +402,12 @@ static int osc_punch(struct obd_export *exp, struct obdo *oa, RETURN(-EINVAL); } - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_PUNCH, 1, &size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_PUNCH, 2, size, NULL); + if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); memcpy(&body->oa, oa, sizeof(*oa)); /* overload the size and blocks fields in the oa with start/end */ @@ -413,14 +415,14 @@ static int osc_punch(struct obd_export *exp, struct obdo *oa, body->oa.o_blocks = end; body->oa.o_valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS); - request->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - body = lustre_swab_repbuf (request, 0, sizeof (*body), - lustre_swab_ost_body); + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) { CERROR ("can't unpack ost_body\n"); GOTO (out, rc = -EPROTO); @@ -430,16 +432,16 @@ static int osc_punch(struct obd_export *exp, struct obdo *oa, EXIT; out: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); return rc; } static int osc_sync(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *md, obd_size start, obd_size end) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; struct ost_body *body; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; if (!oa) { @@ -447,12 +449,12 @@ static int osc_sync(struct obd_export *exp, struct obdo *oa, RETURN(-EINVAL); } - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_SYNC, 1, &size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_SYNC, 2, size, NULL); + if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); memcpy(&body->oa, oa, sizeof(*oa)); /* overload the size and blocks fields in the oa with start/end */ @@ -460,13 +462,13 @@ static int osc_sync(struct obd_export *exp, struct obdo *oa, body->oa.o_blocks = end; body->oa.o_valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS); - request->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - body = lustre_swab_repbuf(request, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_ost_body); if (body == NULL) { CERROR ("can't unpack ost_body\n"); @@ -477,7 +479,7 @@ static int osc_sync(struct obd_export *exp, struct obdo *oa, EXIT; out: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); return rc; } @@ -485,9 +487,9 @@ static int osc_destroy(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *ea, struct obd_trans_info *oti, struct obd_export *md_export) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; struct ost_body *body; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; if (!oa) { @@ -495,12 +497,12 @@ static int osc_destroy(struct obd_export *exp, struct obdo *oa, RETURN(-EINVAL); } - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_DESTROY, 1, &size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_DESTROY, 2, size, NULL); + if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); if (oti != NULL && oa->o_valid & OBD_MD_FLCOOKIE) { memcpy(obdo_logcookie(oa), oti->oti_logcookies, @@ -509,15 +511,15 @@ static int osc_destroy(struct obd_export *exp, struct obdo *oa, } memcpy(&body->oa, oa, sizeof(*oa)); - request->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc == -ENOENT) rc = 0; if (rc) GOTO(out, rc); - body = lustre_swab_repbuf(request, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_ost_body); if (body == NULL) { CERROR ("Can't unpack body\n"); @@ -528,7 +530,7 @@ static int osc_destroy(struct obd_export *exp, struct obdo *oa, EXIT; out: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); return rc; } @@ -677,20 +679,20 @@ static void handle_short_read(int nob_read, obd_count page_count, } } -static int check_write_rcs(struct ptlrpc_request *request, +static int check_write_rcs(struct ptlrpc_request *req, int requested_nob, int niocount, obd_count page_count, struct brw_page **pga) { int *remote_rcs, i; /* return error if any niobuf was in error */ - remote_rcs = lustre_swab_repbuf(request, 1, + remote_rcs = lustre_swab_repbuf(req, REQ_REC_OFF + 1, sizeof(*remote_rcs) * niocount, NULL); if (remote_rcs == NULL) { CERROR("Missing/short RC vector on BRW_WRITE reply\n"); return(-EPROTO); } - if (lustre_msg_swabbed(request->rq_repmsg)) + if (lustre_msg_swabbed(req->rq_repmsg)) for (i = 0; i < niocount; i++) __swab32s(&remote_rcs[i]); @@ -700,14 +702,14 @@ static int check_write_rcs(struct ptlrpc_request *request, if (remote_rcs[i] != 0) { CERROR("rc[%d] invalid (%d) req %p\n", - i, remote_rcs[i], request); + i, remote_rcs[i], req); return(-EPROTO); } } - if (request->rq_bulk->bd_nob_transferred != requested_nob) { + if (req->rq_bulk->bd_nob_transferred != requested_nob) { CERROR("Unexpected # bytes transferred: %d (requested %d)\n", - requested_nob, request->rq_bulk->bd_nob_transferred); + requested_nob, req->rq_bulk->bd_nob_transferred); return(-EPROTO); } @@ -766,12 +768,8 @@ static int osc_brw_prep_request(int cmd, struct obd_import *imp,struct obdo *oa, struct ost_body *body; struct obd_ioobj *ioobj; struct niobuf_remote *niobuf; - int niocount; - int size[3]; - int i; - int requested_nob; - int opc; - int rc; + int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int niocount, i, requested_nob, opc, rc; struct ptlrpc_request_pool *pool; ENTRY; @@ -782,13 +780,12 @@ static int osc_brw_prep_request(int cmd, struct obd_import *imp,struct obdo *oa, if (!can_merge_pages(pga[i - 1], pga[i])) niocount++; - size[0] = sizeof(*body); - size[1] = sizeof(*ioobj); - size[2] = niocount * sizeof(*niobuf); + size[REQ_REC_OFF + 1] = sizeof(*ioobj); + size[REQ_REC_OFF + 2] = niocount * sizeof(*niobuf); OBD_FAIL_RETURN(OBD_FAIL_OSC_BRW_PREP_REQ, -ENOMEM); - req = ptlrpc_prep_req_pool(imp, LUSTRE_OST_VERSION, opc, 3, - size, NULL, pool); + req = ptlrpc_prep_req_pool(imp, LUSTRE_OST_VERSION, opc, 4, size, NULL, + pool); if (req == NULL) RETURN (-ENOMEM); @@ -806,9 +803,10 @@ static int osc_brw_prep_request(int cmd, struct obd_import *imp,struct obdo *oa, GOTO(out, rc = -ENOMEM); /* NB request now owns desc and will free it when it gets freed */ - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body)); - ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj)); - niobuf = lustre_msg_buf(req->rq_reqmsg, 2, niocount * sizeof(*niobuf)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); + ioobj = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*ioobj)); + niobuf = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, + niocount * sizeof(*niobuf)); memcpy(&body->oa, oa, sizeof(*oa)); @@ -854,10 +852,11 @@ static int osc_brw_prep_request(int cmd, struct obd_import *imp,struct obdo *oa, } LASSERT((void *)(niobuf - niocount) == - lustre_msg_buf(req->rq_reqmsg, 2, niocount * sizeof(*niobuf))); + lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, + niocount * sizeof(*niobuf))); osc_announce_cached(cli, &body->oa, opc == OST_WRITE ? requested_nob:0); - /* size[0] still sizeof (*body) */ + /* size[REQ_REC_OFF] still sizeof (*body) */ if (opc == OST_WRITE) { if (unlikely(cli->cl_checksum)) { body->oa.o_valid |= OBD_MD_FLCKSUM; @@ -870,13 +869,13 @@ static int osc_brw_prep_request(int cmd, struct obd_import *imp,struct obdo *oa, oa->o_cksum = body->oa.o_cksum; } /* 1 RC per niobuf */ - size[1] = sizeof(__u32) * niocount; - req->rq_replen = lustre_msg_size(2, size); + size[REPLY_REC_OFF + 1] = sizeof(__u32) * niocount; + ptlrpc_req_set_repsize(req, 3, size); } else { if (unlikely(cli->cl_checksum)) body->oa.o_valid |= OBD_MD_FLCKSUM; /* 1 RC for the whole I/O */ - req->rq_replen = lustre_msg_size(1, size); + ptlrpc_req_set_repsize(req, 2, size); } *niocountp = niocount; @@ -938,14 +937,15 @@ static int osc_brw_fini_request(struct ptlrpc_request *req, struct obdo *oa, RETURN(rc); LASSERTF(req->rq_repmsg != NULL, "rc = %d\n", rc); - body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) { CERROR ("Can't unpack body\n"); RETURN(-EPROTO); } /* set/clear over quota flag for a uid/gid */ - if (req->rq_reqmsg->opc == OST_WRITE && + if (lustre_msg_get_opc(req->rq_reqmsg) == OST_WRITE && body->oa.o_valid & (OBD_MD_FLUSRQUOTA | OBD_MD_FLGRPQUOTA)) lquota_setdq(quota_interface, cli, body->oa.o_uid, body->oa.o_gid, body->oa.o_valid, @@ -960,7 +960,7 @@ static int osc_brw_fini_request(struct ptlrpc_request *req, struct obdo *oa, osc_update_grant(cli, body); memcpy(oa, &body->oa, sizeof(*oa)); - if (req->rq_reqmsg->opc == OST_WRITE) { + if (lustre_msg_get_opc(req->rq_reqmsg) == OST_WRITE) { if (rc > 0) { CERROR ("Unexpected +ve rc %d\n", rc); RETURN(-EPROTO); @@ -1035,33 +1035,33 @@ static int osc_brw_internal(int cmd, struct obd_export *exp,struct obdo *oa, { int requested_nob; int niocount; - struct ptlrpc_request *request; + struct ptlrpc_request *req; int rc; ENTRY; restart_bulk: rc = osc_brw_prep_request(cmd, class_exp2cliimp(exp), oa, lsm, page_count, pga, &requested_nob, &niocount, - &request); + &req); if (rc != 0) return (rc); - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); - if (rc == -ETIMEDOUT && request->rq_resend) { - DEBUG_REQ(D_HA, request, "BULK TIMEOUT"); - ptlrpc_req_finished(request); + if (rc == -ETIMEDOUT && req->rq_resend) { + DEBUG_REQ(D_HA, req, "BULK TIMEOUT"); + ptlrpc_req_finished(req); goto restart_bulk; } - rc = osc_brw_fini_request(request, oa, requested_nob, niocount, + rc = osc_brw_fini_request(req, oa, requested_nob, niocount, page_count, pga, rc); - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); RETURN (rc); } -static int brw_interpret(struct ptlrpc_request *request, +static int brw_interpret(struct ptlrpc_request *req, struct osc_brw_async_args *aa, int rc) { struct obdo *oa = aa->aa_oa; @@ -1071,7 +1071,7 @@ static int brw_interpret(struct ptlrpc_request *request, struct brw_page **pga = aa->aa_ppga; ENTRY; - rc = osc_brw_fini_request(request, oa, requested_nob, niocount, + rc = osc_brw_fini_request(req, oa, requested_nob, niocount, page_count, pga, rc); RETURN (rc); } @@ -1080,7 +1080,7 @@ static int async_internal(int cmd, struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *lsm, obd_count page_count, struct brw_page **pga, struct ptlrpc_request_set *set) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; int requested_nob; int nio_count; struct osc_brw_async_args *aa; @@ -1089,19 +1089,19 @@ static int async_internal(int cmd, struct obd_export *exp, struct obdo *oa, rc = osc_brw_prep_request(cmd, class_exp2cliimp(exp), oa, lsm, page_count, pga, &requested_nob, &nio_count, - &request); + &req); if (rc == 0) { - LASSERT(sizeof(*aa) <= sizeof(request->rq_async_args)); - aa = (struct osc_brw_async_args *)&request->rq_async_args; + LASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); + aa = (struct osc_brw_async_args *)&req->rq_async_args; aa->aa_oa = oa; aa->aa_requested_nob = requested_nob; aa->aa_nio_count = nio_count; aa->aa_page_count = page_count; aa->aa_ppga = pga; - request->rq_interpret_reply = brw_interpret; - ptlrpc_set_add_req(set, request); + req->rq_interpret_reply = brw_interpret; + ptlrpc_set_add_req(set, req); } RETURN (rc); } @@ -1517,7 +1517,7 @@ static void osc_ap_completion(struct client_obd *cli, struct obdo *oa, EXIT; } -static int brw_interpret_oap(struct ptlrpc_request *request, +static int brw_interpret_oap(struct ptlrpc_request *req, struct osc_brw_async_args *aa, int rc) { struct osc_async_page *oap; @@ -1525,11 +1525,11 @@ static int brw_interpret_oap(struct ptlrpc_request *request, struct list_head *pos, *n; ENTRY; - rc = osc_brw_fini_request(request, aa->aa_oa, aa->aa_requested_nob, + rc = osc_brw_fini_request(req, aa->aa_oa, aa->aa_requested_nob, aa->aa_nio_count, aa->aa_page_count, aa->aa_ppga, rc); - CDEBUG(D_INODE, "request %p aa %p rc %d\n", request, aa, rc); + CDEBUG(D_INODE, "request %p aa %p rc %d\n", req, aa, rc); cli = aa->aa_cli; @@ -1538,7 +1538,7 @@ static int brw_interpret_oap(struct ptlrpc_request *request, /* We need to decrement before osc_ap_completion->osc_wake_cache_waiters * is called so we know whether to go to sync BRWs or wait for more * RPCs to complete */ - if (request->rq_reqmsg->opc == OST_WRITE) + if (lustre_msg_get_opc(req->rq_reqmsg) == OST_WRITE) cli->cl_w_in_flight--; else cli->cl_r_in_flight--; @@ -1646,7 +1646,7 @@ out: static int osc_send_oap_rpc(struct client_obd *cli, struct lov_oinfo *loi, int cmd, struct loi_oap_pages *lop) { - struct ptlrpc_request *request; + struct ptlrpc_request *req; obd_count page_count = 0; struct list_head *tmp, *pos; struct osc_async_page *oap = NULL; @@ -1773,8 +1773,8 @@ static int osc_send_oap_rpc(struct client_obd *cli, struct lov_oinfo *loi, client_obd_list_unlock(&cli->cl_loi_list_lock); - request = osc_build_req(cli, &rpc_list, page_count, cmd); - if (IS_ERR(request)) { + req = osc_build_req(cli, &rpc_list, page_count, cmd); + if (IS_ERR(req)) { /* this should happen rarely and is pretty bad, it makes the * pending list not follow the dirty order */ client_obd_list_lock(&cli->cl_loi_list_lock); @@ -1791,14 +1791,14 @@ static int osc_send_oap_rpc(struct client_obd *cli, struct lov_oinfo *loi, oap->oap_count); continue; } - osc_ap_completion(cli, NULL, oap, 0, PTR_ERR(request)); + osc_ap_completion(cli, NULL, oap, 0, PTR_ERR(req)); } loi_list_maint(cli, loi); - RETURN(PTR_ERR(request)); + RETURN(PTR_ERR(req)); } - LASSERT(sizeof(*aa) <= sizeof(request->rq_async_args)); - aa = (struct osc_brw_async_args *)&request->rq_async_args; + LASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); + aa = (struct osc_brw_async_args *)&req->rq_async_args; CFS_INIT_LIST_HEAD(&aa->aa_oaps); list_splice(&rpc_list, &aa->aa_oaps); CFS_INIT_LIST_HEAD(&rpc_list); @@ -1829,19 +1829,19 @@ static int osc_send_oap_rpc(struct client_obd *cli, struct lov_oinfo *loi, oap = list_entry(pos, struct osc_async_page, oap_rpc_item); if (oap->oap_interrupted) { CDEBUG(D_INODE, "oap %p in req %p interrupted\n", - oap, request); - ptlrpc_mark_interrupted(request); + oap, req); + ptlrpc_mark_interrupted(req); break; } } CDEBUG(D_INODE, "req %p: %d pages, aa %p. now %dr/%dw in flight\n", - request, page_count, aa, cli->cl_r_in_flight, + req, page_count, aa, cli->cl_r_in_flight, cli->cl_w_in_flight); - oap->oap_request = ptlrpc_request_addref(request); - request->rq_interpret_reply = brw_interpret_oap; - ptlrpcd_add_req(request); + oap->oap_request = ptlrpc_request_addref(req); + req->rq_interpret_reply = brw_interpret_oap; + ptlrpcd_add_req(req); RETURN(1); } @@ -2383,33 +2383,34 @@ static int sanosc_brw_read(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *lsm, obd_count page_count, struct brw_page *pga) { - struct ptlrpc_request *request = NULL; + struct ptlrpc_request *req = NULL; struct ost_body *body; struct niobuf_remote *nioptr; struct obd_ioobj *iooptr; - int rc, size[3] = {sizeof(*body)}, mapped = 0; struct obd_import *imp = class_exp2cliimp(exp); - int swab; + int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body)}; + int swab, mapped = 0, rc; ENTRY; /* XXX does not handle 'new' brw protocol */ - size[1] = sizeof(struct obd_ioobj); - size[2] = page_count * sizeof(*nioptr); + size[REQ_REC_OFF + 1] = sizeof(struct obd_ioobj); + size[REQ_REC_OFF + 2] = page_count * sizeof(*nioptr); - request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_SAN_READ, 3, size, NULL); - if (!request) + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_SAN_READ, 4, size, NULL); + if (!req) RETURN(-ENOMEM); /* FIXME bug 249 */ /* See bug 7198 */ if (imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_REQPORTAL) - request->rq_request_portal = OST_IO_PORTAL; + req->rq_request_portal = OST_IO_PORTAL; - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*body)); - iooptr = lustre_msg_buf(request->rq_reqmsg, 1, sizeof(*iooptr)); - nioptr = lustre_msg_buf(request->rq_reqmsg, 2, + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); + iooptr = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, + sizeof(*iooptr)); + nioptr = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, sizeof(*nioptr) * page_count); memcpy(&body->oa, oa, sizeof(body->oa)); @@ -2426,14 +2427,14 @@ static int sanosc_brw_read(struct obd_export *exp, struct obdo *oa, nioptr->flags = pga[mapped].flag; } - size[1] = page_count * sizeof(*nioptr); - request->rq_replen = lustre_msg_size(2, size); + size[REPLY_REC_OFF + 1] = page_count * sizeof(*nioptr); + ptlrpc_req_set_repsize(req, 3, size); - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc) GOTO(out_req, rc); - body = lustre_swab_repbuf(request, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_ost_body); if (body == NULL) { CERROR("Can't unpack body\n"); @@ -2442,9 +2443,10 @@ static int sanosc_brw_read(struct obd_export *exp, struct obdo *oa, memcpy(oa, &body->oa, sizeof(*oa)); - swab = lustre_msg_swabbed(request->rq_repmsg); - LASSERT_REPSWAB(request, 1); - nioptr = lustre_msg_buf(request->rq_repmsg, 1, size[1]); + swab = lustre_msg_swabbed(req->rq_repmsg); + LASSERT_REPSWAB(req, REPLY_REC_OFF + 1); + nioptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, + size[REPLY_REC_OFF + 1]); if (!nioptr) { /* nioptr missing or short */ GOTO(out_req, rc = -EPROTO); @@ -2511,7 +2513,7 @@ static int sanosc_brw_read(struct obd_export *exp, struct obdo *oa, } out_req: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); RETURN(rc); } @@ -2519,33 +2521,33 @@ static int sanosc_brw_write(struct obd_export *exp, struct obdo *oa, struct lov_stripe_md *lsm, obd_count page_count, struct brw_page *pga) { - struct ptlrpc_request *request = NULL; + struct ptlrpc_request *req = NULL; struct ost_body *body; struct niobuf_remote *nioptr; struct obd_ioobj *iooptr; struct obd_import *imp = class_exp2cliimp(exp); - int rc, size[3] = {sizeof(*body)}, mapped = 0; - int swab; + int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int swab, mapped = 0, rc; ENTRY; - size[1] = sizeof(struct obd_ioobj); - size[2] = page_count * sizeof(*nioptr); + size[REQ_REC_OFF + 1] = sizeof(struct obd_ioobj); + size[REQ_REC_OFF + 2] = page_count * sizeof(*nioptr); - request = ptlrpc_prep_req_pool(class_exp2cliimp(exp), - LUSTRE_OST_VERSION, OST_SAN_WRITE, - 3, size, NULL, imp->imp_rq_pool); - if (!request) + req = ptlrpc_prep_req_pool(class_exp2cliimp(exp), LUSTRE_OST_VERSION, + OST_SAN_WRITE, 4, size, NULL, imp->imp_rq_pool); + if (!req) RETURN(-ENOMEM); /* FIXME bug 249 */ /* See bug 7198 */ if (imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_REQPORTAL) - request->rq_request_portal = OST_IO_PORTAL; + req->rq_request_portal = OST_IO_PORTAL; - body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body)); - iooptr = lustre_msg_buf(request->rq_reqmsg, 1, sizeof (*iooptr)); - nioptr = lustre_msg_buf(request->rq_reqmsg, 2, - sizeof (*nioptr) * page_count); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); + iooptr = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, + sizeof(*iooptr)); + nioptr = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, + sizeof(*nioptr) * page_count); memcpy(&body->oa, oa, sizeof(body->oa)); @@ -2562,16 +2564,17 @@ static int sanosc_brw_write(struct obd_export *exp, struct obdo *oa, nioptr->flags = pga[mapped].flag; } - size[1] = page_count * sizeof(*nioptr); - request->rq_replen = lustre_msg_size(2, size); + size[REPLY_REC_OFF + 1] = page_count * sizeof(*nioptr); + ptlrpc_req_set_repsize(req, 3, size); - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc) GOTO(out_req, rc); - swab = lustre_msg_swabbed (request->rq_repmsg); - LASSERT_REPSWAB (request, 1); - nioptr = lustre_msg_buf(request->rq_repmsg, 1, size[1]); + swab = lustre_msg_swabbed (req->rq_repmsg); + LASSERT_REPSWAB(req, REPLY_REC_OFF + 1); + nioptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, + size[REPLY_REC_OFF + 1]); if (!nioptr) { CERROR("absent/short niobuf array\n"); GOTO(out_req, rc = -EPROTO); @@ -2631,7 +2634,7 @@ static int sanosc_brw_write(struct obd_export *exp, struct obdo *oa, } out_req: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); RETURN(rc); } @@ -2772,16 +2775,18 @@ static int osc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm, no_match: if (*flags & LDLM_FL_HAS_INTENT) { - int size[2] = {sizeof(struct ldlm_request), sizeof(lvb)}; + int size[3] = { + [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), + [DLM_LOCKREQ_OFF] = sizeof(struct ldlm_request) }; - req = ptlrpc_prep_req(class_exp2cliimp(exp), - LUSTRE_DLM_VERSION, LDLM_ENQUEUE, 1, - size, NULL); + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION, + LDLM_ENQUEUE, 2, size, NULL); if (req == NULL) RETURN(-ENOMEM); - size[0] = sizeof(*rep); - req->rq_replen = lustre_msg_size(2, size); + size[DLM_LOCKREPLY_OFF] = sizeof(*rep); + size[DLM_REPLY_REC_OFF] = sizeof(lvb); + ptlrpc_req_set_repsize(req, 3, size); } /* users of osc_enqueue() can pass this flag for ldlm_lock_match() */ @@ -2794,8 +2799,9 @@ static int osc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm, if (req != NULL) { if (rc == ELDLM_LOCK_ABORTED) { /* swabbed by ldlm_cli_enqueue() */ - LASSERT_REPSWABBED(req, 0); - rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep)); + LASSERT_REPSWABBED(req, DLM_LOCKREPLY_OFF); + rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, + sizeof(*rep)); LASSERT(rep != NULL); if (rep->lock_policy_res1) rc = rep->lock_policy_res1; @@ -2890,8 +2896,8 @@ static int osc_statfs(struct obd_device *obd, struct obd_statfs *osfs, cfs_time_t max_age) { struct obd_statfs *msfs; - struct ptlrpc_request *request; - int rc, size = sizeof(*osfs); + struct ptlrpc_request *req; + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) }; ENTRY; /* We could possibly pass max_age in the request (as an absolute @@ -2900,19 +2906,19 @@ static int osc_statfs(struct obd_device *obd, struct obd_statfs *osfs, * during mount that would help a bit). Having relative timestamps * is not so great if request processing is slow, while absolute * timestamps are not ideal because they need time synchronization. */ - request = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_OST_VERSION, - OST_STATFS,0,NULL,NULL); - if (!request) + req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_OST_VERSION, + OST_STATFS, 1, NULL, NULL); + if (!req) RETURN(-ENOMEM); - request->rq_replen = lustre_msg_size(1, &size); - request->rq_request_portal = OST_CREATE_PORTAL; //XXX FIXME bug 249 + ptlrpc_req_set_repsize(req, 2, size); + req->rq_request_portal = OST_CREATE_PORTAL; //XXX FIXME bug 249 - rc = ptlrpc_queue_wait(request); + rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - msfs = lustre_swab_repbuf(request, 0, sizeof(*msfs), + msfs = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*msfs), lustre_swab_obd_statfs); if (msfs == NULL) { CERROR("Can't unpack obd_statfs\n"); @@ -2923,7 +2929,7 @@ static int osc_statfs(struct obd_device *obd, struct obd_statfs *osfs, EXIT; out: - ptlrpc_req_finished(request); + ptlrpc_req_finished(req); return rc; } @@ -3081,19 +3087,21 @@ static int osc_get_info(struct obd_export *exp, obd_count keylen, } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) { struct ptlrpc_request *req; obd_id *reply; - char *bufs[1] = {key}; - int rc; + char *bufs[2] = { NULL, key }; + int rc, size[2] = { sizeof(struct ptlrpc_body), keylen }; + req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION, - OST_GET_INFO, 1, &keylen, bufs); + OST_GET_INFO, 2, size, bufs); if (req == NULL) RETURN(-ENOMEM); - req->rq_replen = lustre_msg_size(1, vallen); + size[REPLY_REC_OFF] = *vallen; + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - reply = lustre_swab_repbuf(req, 0, sizeof(*reply), + reply = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*reply), lustre_swab_ost_last_id); if (reply == NULL) { CERROR("Can't unpack OST last ID\n"); @@ -3140,8 +3148,8 @@ static int osc_set_info_async(struct obd_export *exp, obd_count keylen, struct ptlrpc_request *req; struct obd_device *obd = exp->exp_obd; struct obd_import *imp = class_exp2cliimp(exp); - int size[2] = {keylen, vallen}; - char *bufs[2] = {key, val}; + int size[3] = { sizeof(struct ptlrpc_body), keylen, vallen }; + char *bufs[3] = { NULL, key, val }; ENTRY; OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_SHUTDOWN, 10); @@ -3192,15 +3200,15 @@ static int osc_set_info_async(struct obd_export *exp, obd_count keylen, Even if something bad goes through, we'd get a -EINVAL from OST anyway. */ - req = ptlrpc_prep_req(imp, LUSTRE_OST_VERSION, OST_SET_INFO, - 2, size, bufs); + req = ptlrpc_prep_req(imp, LUSTRE_OST_VERSION, OST_SET_INFO, 3, size, + bufs); if (req == NULL) RETURN(-ENOMEM); - req->rq_replen = lustre_msg_size(0, NULL); - if (KEY_IS("mds_conn")) req->rq_interpret_reply = osc_setinfo_mds_conn_interpret; + + ptlrpc_req_set_repsize(req, 1, NULL); ptlrpc_set_add_req(set, req); ptlrpc_check_set(set); diff --git a/lustre/ost/lproc_ost.c b/lustre/ost/lproc_ost.c index 7b8e790..38f9518 100644 --- a/lustre/ost/lproc_ost.c +++ b/lustre/ost/lproc_ost.c @@ -60,13 +60,13 @@ ost_print_req(void *seq_file, struct ptlrpc_request *req) case RQ_PHASE_INTERPRET: /* being handled, so basic msg swabbed, and opc is valid * but racing with ost_handle() */ - seq_printf(sf, "opc %d\n", req->rq_reqmsg->opc); + seq_printf(sf, "opc %d\n", lustre_msg_get_opc(req->rq_reqmsg)); break; case RQ_PHASE_COMPLETE: /* been handled by ost_handle() reply state possibly still * volatile */ - seq_printf(sf, "opc %d\n", req->rq_reqmsg->opc); + seq_printf(sf, "opc %d\n", lustre_msg_get_opc(req->rq_reqmsg)); break; default: diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c index 3d56caf..b9ac3d9 100644 --- a/lustre/ost/ost_handler.c +++ b/lustre/ost/ost_handler.c @@ -64,7 +64,7 @@ void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req) return; if (req->rq_repmsg) - req->rq_repmsg->transno = oti->oti_transno; + lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno); req->rq_transno = oti->oti_transno; /* XXX 4 == entries in oti_ack_locks??? */ @@ -80,20 +80,22 @@ static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req, struct obd_trans_info *oti) { struct ost_body *body, *repbody; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) RETURN(-EFAULT); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); if (body->oa.o_valid & OBD_MD_FLCOOKIE) oti->oti_logcookies = obdo_logcookie(&body->oa); - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); memcpy(&repbody->oa, &body->oa, sizeof(body->oa)); req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL); RETURN(0); @@ -102,18 +104,20 @@ static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req, static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req) { struct ost_body *body, *repbody; - int rc, size = sizeof(*body); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) RETURN(-EFAULT); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); memcpy(&repbody->oa, &body->oa, sizeof(body->oa)); req->rq_status = obd_getattr(exp, &repbody->oa, NULL); RETURN(0); @@ -122,14 +126,14 @@ static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req) static int ost_statfs(struct ptlrpc_request *req) { struct obd_statfs *osfs; - int rc, size = sizeof(*osfs); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) }; ENTRY; - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - osfs = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*osfs)); + osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs)); req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs, jiffies-HZ); if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC)) @@ -144,18 +148,20 @@ static int ost_create(struct obd_export *exp, struct ptlrpc_request *req, struct obd_trans_info *oti) { struct ost_body *body, *repbody; - int rc, size = sizeof(*repbody); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) }; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) RETURN(-EFAULT); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); memcpy(&repbody->oa, &body->oa, sizeof(body->oa)); oti->oti_logcookies = obdo_logcookie(&repbody->oa); req->rq_status = obd_create(exp, &repbody->oa, NULL, oti); @@ -231,18 +237,15 @@ static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req, { struct obdo *oa; struct ost_body *body, *repbody; + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) }; struct lustre_handle lh = {0,}; - - int rc, size = sizeof(*repbody); - ENTRY; - /* - * check that we do support OBD_CONNECT_TRUNCLOCK. - */ + /* check that we do support OBD_CONNECT_TRUNCLOCK. */ CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK); - body = lustre_swab_reqbuf(req, 0, sizeof *body, lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) RETURN(-EFAULT); @@ -251,11 +254,12 @@ static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req, (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) RETURN(-EINVAL); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); repbody->oa = *oa; rc = ost_punch_lock_get(exp, oa, &lh); if (rc == 0) { @@ -278,18 +282,20 @@ static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req, static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req) { struct ost_body *body, *repbody; - int rc, size = sizeof(*repbody); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) }; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) RETURN(-EFAULT); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); memcpy(&repbody->oa, &body->oa, sizeof(body->oa)); req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size, repbody->oa.o_blocks); @@ -300,18 +306,20 @@ static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req, struct obd_trans_info *oti) { struct ost_body *body, *repbody; - int rc, size = sizeof(*repbody); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) }; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) RETURN(-EFAULT); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); memcpy(&repbody->oa, &body->oa, sizeof(body->oa)); req->rq_status = obd_setattr(exp, &repbody->oa, NULL, oti); @@ -650,20 +658,15 @@ static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj, static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti) { struct ptlrpc_bulk_desc *desc; - struct niobuf_remote *remote_nb; - struct niobuf_remote *pp_rnb = NULL; - struct niobuf_local *local_nb; - struct obd_ioobj *ioo; - struct ost_body *body, *repbody; - struct l_wait_info lwi; - struct lustre_handle lockh = {0}; - int size[1] = { sizeof(*body) }; - int comms_error = 0; - int niocount; - int npages; - int nob = 0; - int rc; - int i, do_checksum; + struct niobuf_remote *remote_nb; + struct niobuf_remote *pp_rnb = NULL; + struct niobuf_local *local_nb; + struct obd_ioobj *ioo; + struct ost_body *body, *repbody; + struct l_wait_info lwi; + struct lustre_handle lockh = { 0 }; + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int comms_error = 0, niocount, npages, nob = 0, rc, i, do_checksum; ENTRY; if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK)) @@ -672,13 +675,15 @@ static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti) OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE, (obd_timeout + 1) / 4); - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) { CERROR("Missing/short ost_body\n"); GOTO(out, rc = -EFAULT); } - ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj); + ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo), + lustre_swab_obd_ioobj); if (ioo == NULL) { CERROR("Missing/short ioobj\n"); GOTO(out, rc = -EFAULT); @@ -691,7 +696,8 @@ static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti) GOTO(out, rc = -EFAULT); } - remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb), + remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2, + niocount * sizeof(*remote_nb), lustre_swab_niobuf_remote); if (remote_nb == NULL) { CERROR("Missing/short niobuf\n"); @@ -702,7 +708,7 @@ static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti) lustre_swab_niobuf_remote (&remote_nb[i]); } - rc = lustre_pack_reply(req, 1, size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) GOTO(out, rc); @@ -814,7 +820,8 @@ static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti) ost_nio_pages_put(req, local_nb, npages); if (rc == 0) { - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa)); if (unlikely(do_checksum)) { @@ -867,10 +874,9 @@ static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti) struct l_wait_info lwi; struct lustre_handle lockh = {0}; __u32 *rcs; - int size[2] = { sizeof(*body) }; - int objcount, niocount, npages; - int comms_error = 0; - int rc, swab, i, j, do_checksum; + int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int objcount, niocount, npages, comms_error = 0; + int rc, swab, i, j, do_checksum; ENTRY; if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK)) @@ -881,14 +887,16 @@ static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti) (obd_timeout + 1) / 4); swab = lustre_msg_swabbed(req->rq_reqmsg); - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) { CERROR("Missing/short ost_body\n"); GOTO(out, rc = -EFAULT); } - LASSERT_REQSWAB(req, 1); - objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo); + LASSERT_REQSWAB(req, REQ_REC_OFF + 1); + objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) / + sizeof(*ioo); if (objcount == 0) { CERROR("Missing/short ioobj\n"); GOTO(out, rc = -EFAULT); @@ -898,11 +906,12 @@ static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti) GOTO(out, rc = -EFAULT); } - ioo = lustre_msg_buf (req->rq_reqmsg, 1, objcount * sizeof(*ioo)); + ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, + objcount * sizeof(*ioo)); LASSERT (ioo != NULL); for (niocount = i = 0; i < objcount; i++) { if (swab) - lustre_swab_obd_ioobj (&ioo[i]); + lustre_swab_obd_ioobj(&ioo[i]); if (ioo[i].ioo_bufcnt == 0) { CERROR("ioo[%d] has zero bufcnt\n", i); GOTO(out, rc = -EFAULT); @@ -916,7 +925,8 @@ static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti) GOTO(out, rc = -EFAULT); } - remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb), + remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2, + niocount * sizeof(*remote_nb), lustre_swab_niobuf_remote); if (remote_nb == NULL) { CERROR("Missing/short niobuf\n"); @@ -927,11 +937,12 @@ static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti) lustre_swab_niobuf_remote (&remote_nb[i]); } - size[1] = niocount * sizeof(*rcs); - rc = lustre_pack_reply(req, 2, size, NULL); + size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs); + rc = lustre_pack_reply(req, 3, size, NULL); if (rc != 0) GOTO(out, rc); - rcs = lustre_msg_buf(req->rq_repmsg, 1, niocount * sizeof(*rcs)); + rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, + niocount * sizeof(*rcs)); /* * Per-thread array of struct niobuf_{local,remote}'s was allocated by @@ -1009,7 +1020,8 @@ static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti) } comms_error = rc != 0; - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa)); if (unlikely(do_checksum && rc == 0)) { @@ -1096,25 +1108,28 @@ static int ost_san_brw(struct ptlrpc_request *req, int cmd) struct niobuf_remote *remote_nb, *res_nb, *pp_rnb = NULL; struct obd_ioobj *ioo; struct ost_body *body, *repbody; - int rc, i, objcount, niocount, size[2] = {sizeof(*body)}, npages; - int swab; + int rc, i, objcount, niocount, npages, swab; + int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) }; ENTRY; /* XXX not set to use latest protocol */ swab = lustre_msg_swabbed(req->rq_reqmsg); - body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body); + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), + lustre_swab_ost_body); if (body == NULL) { CERROR("Missing/short ost_body\n"); GOTO(out, rc = -EFAULT); } - ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj); + ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo), + lustre_swab_obd_ioobj); if (ioo == NULL) { CERROR("Missing/short ioobj\n"); GOTO(out, rc = -EFAULT); } - objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo); + objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) / + sizeof(*ioo); niocount = ioo[0].ioo_bufcnt; for (i = 1; i < objcount; i++) { if (swab) @@ -1122,7 +1137,8 @@ static int ost_san_brw(struct ptlrpc_request *req, int cmd) niocount += ioo[i].ioo_bufcnt; } - remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb), + remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2, + niocount * sizeof(*remote_nb), lustre_swab_niobuf_remote); if (remote_nb == NULL) { CERROR("Missing/short niobuf\n"); @@ -1144,8 +1160,8 @@ static int ost_san_brw(struct ptlrpc_request *req, int cmd) if (npages < 0) GOTO (out, rc = npages); - size[1] = npages * sizeof(*pp_rnb); - rc = lustre_pack_reply(req, 2, size, NULL); + size[REPLY_REC_OFF + 1] = npages * sizeof(*pp_rnb); + rc = lustre_pack_reply(req, 3, size, NULL); if (rc) GOTO(out, rc); @@ -1155,11 +1171,13 @@ static int ost_san_brw(struct ptlrpc_request *req, int cmd) if (req->rq_status) GOTO(out, rc = 0); - repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody)); + repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, + sizeof(*repbody)); memcpy(&repbody->oa, &body->oa, sizeof(body->oa)); - res_nb = lustre_msg_buf(req->rq_repmsg, 1, size[1]); - memcpy(res_nb, remote_nb, size[1]); + res_nb = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, + size[REPLY_REC_OFF + 1]); + memcpy(res_nb, remote_nb, size[REPLY_REC_OFF + 1]); rc = 0; out: target_committed_to_req(req); @@ -1180,20 +1198,20 @@ static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req) int keylen, vallen, rc = 0; ENTRY; - key = lustre_msg_buf(req->rq_reqmsg, 0, 1); + key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1); if (key == NULL) { DEBUG_REQ(D_HA, req, "no set_info key"); RETURN(-EFAULT); } - keylen = lustre_msg_buflen(req->rq_reqmsg,0); + keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF); - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) RETURN(rc); - vallen = lustre_msg_buflen(req->rq_reqmsg, 1); + vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1); if (vallen) - val = lustre_msg_buf(req->rq_reqmsg, 1, 0); + val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0); if (KEY_IS("evict_by_nid")) { if (val && vallen) @@ -1204,53 +1222,54 @@ static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req) rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL); out: - req->rq_repmsg->status = 0; + lustre_msg_set_status(req->rq_repmsg, 0); RETURN(rc); } static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req) { char *key; - int keylen, rc = 0, size = sizeof(obd_id); + int keylen, rc = 0; + int size[2] = { sizeof(struct ptlrpc_body), sizeof(obd_id) }; obd_id *reply; ENTRY; - key = lustre_msg_buf(req->rq_reqmsg, 0, 1); + key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1); if (key == NULL) { DEBUG_REQ(D_HA, req, "no get_info key"); RETURN(-EFAULT); } - keylen = req->rq_reqmsg->buflens[0]; + keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF); if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0) RETURN(-EPROTO); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) RETURN(rc); - reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply)); - rc = obd_get_info(exp, keylen, key, &size, reply); - req->rq_repmsg->status = 0; + reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply)); + rc = obd_get_info(exp, keylen, key, size, reply); + lustre_msg_set_status(req->rq_repmsg, 0); RETURN(rc); } static int ost_handle_quotactl(struct ptlrpc_request *req) { struct obd_quotactl *oqctl, *repoqc; - int rc, size = sizeof(*repoqc); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) }; ENTRY; - oqctl = lustre_swab_reqbuf(req, 0, sizeof(*oqctl), + oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl), lustre_swab_obd_quotactl); if (oqctl == NULL) GOTO(out, rc = -EPROTO); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) GOTO(out, rc); - repoqc = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repoqc)); + repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc)); req->rq_status = obd_quotactl(req->rq_export, oqctl); *repoqc = *oqctl; @@ -1264,12 +1283,12 @@ static int ost_handle_quotacheck(struct ptlrpc_request *req) int rc; ENTRY; - oqctl = lustre_swab_reqbuf(req, 0, sizeof(*oqctl), + oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl), lustre_swab_obd_quotactl); if (oqctl == NULL) RETURN(-EPROTO); - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) { CERROR("ost: out of memory while packing quotacheck reply\n"); RETURN(-ENOMEM); @@ -1282,7 +1301,7 @@ static int ost_handle_quotacheck(struct ptlrpc_request *req) static int ost_filter_recovery_request(struct ptlrpc_request *req, struct obd_device *obd, int *process) { - switch (req->rq_reqmsg->opc) { + switch (lustre_msg_get_opc(req->rq_reqmsg)) { case OST_CONNECT: /* This will never get here, but for completeness. */ case OST_DISCONNECT: *process = 1; @@ -1313,18 +1332,16 @@ int ost_msg_check_version(struct lustre_msg *msg) { int rc; - /* TODO: enable the below check while really introducing msg version. - * it's disabled because it will break compatibility with b1_4. - */ - return (0); - switch(msg->opc) { + switch(lustre_msg_get_opc(msg)) { case OST_CONNECT: case OST_DISCONNECT: case OBD_PING: rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION); if (rc) CERROR("bad opc %u version %08x, expecting %08x\n", - msg->opc, msg->version, LUSTRE_OBD_VERSION); + lustre_msg_get_opc(msg), + lustre_msg_get_version(msg), + LUSTRE_OBD_VERSION); break; case OST_CREATE: case OST_DESTROY: @@ -1344,7 +1361,9 @@ int ost_msg_check_version(struct lustre_msg *msg) rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION); if (rc) CERROR("bad opc %u version %08x, expecting %08x\n", - msg->opc, msg->version, LUSTRE_OST_VERSION); + lustre_msg_get_opc(msg), + lustre_msg_get_version(msg), + LUSTRE_OST_VERSION); break; case LDLM_ENQUEUE: case LDLM_CONVERT: @@ -1354,16 +1373,21 @@ int ost_msg_check_version(struct lustre_msg *msg) rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION); if (rc) CERROR("bad opc %u version %08x, expecting %08x\n", - msg->opc, msg->version, LUSTRE_DLM_VERSION); + lustre_msg_get_opc(msg), + lustre_msg_get_version(msg), + LUSTRE_DLM_VERSION); break; case LLOG_ORIGIN_CONNECT: case OBD_LOG_CANCEL: rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION); if (rc) CERROR("bad opc %u version %08x, expecting %08x\n", - msg->opc, msg->version, LUSTRE_LOG_VERSION); + lustre_msg_get_opc(msg), + lustre_msg_get_version(msg), + LUSTRE_LOG_VERSION); + break; default: - CERROR("Unexpected opcode %d\n", msg->opc); + CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg)); rc = -ENOTSUPP; } return rc; @@ -1379,12 +1403,13 @@ static int ost_handle(struct ptlrpc_request *req) LASSERT(current->journal_info == NULL); /* XXX identical to MDS */ - if (req->rq_reqmsg->opc != OST_CONNECT) { + if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) { int abort_recovery, recovering; if (req->rq_export == NULL) { CDEBUG(D_HA,"operation %d on unconnected OST from %s\n", - req->rq_reqmsg->opc, libcfs_id2str(req->rq_peer)); + lustre_msg_get_opc(req->rq_reqmsg), + libcfs_id2str(req->rq_peer)); req->rq_status = -ENOTCONN; GOTO(out, rc = -ENOTCONN); } @@ -1411,7 +1436,11 @@ static int ost_handle(struct ptlrpc_request *req) if (rc) RETURN(rc); - switch (req->rq_reqmsg->opc) { + rc = ost_msg_check_version(req->rq_reqmsg); + if (rc) + RETURN(rc); + + switch (lustre_msg_get_opc(req->rq_reqmsg)) { case OST_CONNECT: { CDEBUG(D_INODE, "connect\n"); OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0); @@ -1525,7 +1554,7 @@ static int ost_handle(struct ptlrpc_request *req) DEBUG_REQ(D_INODE, req, "log connect\n"); rc = llog_handle_connect(req); req->rq_status = rc; - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) RETURN(rc); RETURN(ptlrpc_reply(req)); @@ -1534,7 +1563,7 @@ static int ost_handle(struct ptlrpc_request *req) OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0); rc = llog_origin_handle_cancel(req); req->rq_status = rc; - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) RETURN(rc); RETURN(ptlrpc_reply(req)); @@ -1562,7 +1591,8 @@ static int ost_handle(struct ptlrpc_request *req) CERROR("callbacks should not happen on OST\n"); /* fall through */ default: - CERROR("Unexpected opcode %d\n", req->rq_reqmsg->opc); + CERROR("Unexpected opcode %d\n", + lustre_msg_get_opc(req->rq_reqmsg)); req->rq_status = -ENOTSUPP; rc = ptlrpc_error(req); RETURN(rc); @@ -1572,7 +1602,7 @@ static int ost_handle(struct ptlrpc_request *req) EXIT; /* If we're DISCONNECTing, the export_data is already freed */ - if (!rc && req->rq_reqmsg->opc != OST_DISCONNECT) + if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT) target_committed_to_req(req); out: diff --git a/lustre/ptlrpc/client.c b/lustre/ptlrpc/client.c index 2732e53..230d065 100644 --- a/lustre/ptlrpc/client.c +++ b/lustre/ptlrpc/client.c @@ -330,18 +330,16 @@ ptlrpc_prep_req_pool(struct obd_import *imp, __u32 version, int opcode, RETURN(NULL); } - rc = lustre_pack_request(request, count, lengths, bufs); + rc = lustre_pack_request(request, imp->imp_msg_magic, count, lengths, + bufs); if (rc) { LASSERT(!request->rq_pool); OBD_FREE(request, sizeof(*request)); RETURN(NULL); } -#if 0 /* TODO: enable this while really introducing msg version. - * it's disabled because it will break compatibility with b1_4. - */ - request->rq_reqmsg->version |= version; -#endif + lustre_msg_add_version(request->rq_reqmsg, version); + if (imp->imp_server_timeout) request->rq_timeout = obd_timeout / 2; else @@ -371,18 +369,18 @@ ptlrpc_prep_req_pool(struct obd_import *imp, __u32 version, int opcode, request->rq_xid = ptlrpc_next_xid(); atomic_set(&request->rq_refcount, 1); - request->rq_reqmsg->opc = opcode; - request->rq_reqmsg->flags = 0; + lustre_msg_set_opc(request->rq_reqmsg, opcode); + lustre_msg_set_flags(request->rq_reqmsg, 0); RETURN(request); } struct ptlrpc_request * -ptlrpc_prep_req(struct obd_import *imp, __u32 version, int opcode, - int count, int *lengths, char **bufs) +ptlrpc_prep_req(struct obd_import *imp, __u32 version, int opcode, int count, + int *lengths, char **bufs) { - return ptlrpc_prep_req_pool(imp, version, opcode, count, lengths, - bufs, NULL); + return ptlrpc_prep_req_pool(imp, version, opcode, count, lengths, bufs, + NULL); } struct ptlrpc_request_set *ptlrpc_prep_set(void) @@ -537,7 +535,7 @@ static int ptlrpc_check_reply(struct ptlrpc_request *req) ENTRY; /* serialise with network callback */ - spin_lock_irqsave (&req->rq_lock, flags); + spin_lock_irqsave(&req->rq_lock, flags); if (req->rq_replied) { DEBUG_REQ(D_NET, req, "REPLIED:"); @@ -567,7 +565,7 @@ static int ptlrpc_check_reply(struct ptlrpc_request *req) } EXIT; out: - spin_unlock_irqrestore (&req->rq_lock, flags); + spin_unlock_irqrestore(&req->rq_lock, flags); DEBUG_REQ(D_NET, req, "rc = %d for", rc); return rc; } @@ -577,8 +575,8 @@ static int ptlrpc_check_status(struct ptlrpc_request *req) int err; ENTRY; - err = req->rq_repmsg->status; - if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) { + err = lustre_msg_get_status(req->rq_repmsg); + if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) { DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err == %d", err); RETURN(err < 0 ? err : -EINVAL); @@ -617,10 +615,16 @@ static int after_reply(struct ptlrpc_request *req) RETURN(-EPROTO); } - if (req->rq_repmsg->type != PTL_RPC_MSG_REPLY && - req->rq_repmsg->type != PTL_RPC_MSG_ERR) { + rc = lustre_unpack_ptlrpc_body(req->rq_repmsg); + if (rc) { + DEBUG_REQ(D_ERROR, req, "unpack ptlrpc body failed: %d\n", rc); + RETURN(-EPROTO); + } + + if (lustre_msg_get_type(req->rq_repmsg) != PTL_RPC_MSG_REPLY && + lustre_msg_get_type(req->rq_repmsg) != PTL_RPC_MSG_ERR) { DEBUG_REQ(D_ERROR, req, "invalid packet received (type=%u)\n", - req->rq_repmsg->type); + lustre_msg_get_type(req->rq_repmsg)); RETURN(-EPROTO); } @@ -641,7 +645,8 @@ static int after_reply(struct ptlrpc_request *req) } /* Store transno in reqmsg for replay. */ - req->rq_reqmsg->transno = req->rq_transno = req->rq_repmsg->transno; + req->rq_transno = lustre_msg_get_transno(req->rq_repmsg); + lustre_msg_set_transno(req->rq_reqmsg, req->rq_transno); if (req->rq_import->imp_replayable) { spin_lock_irqsave(&imp->imp_lock, flags); @@ -654,9 +659,9 @@ static int after_reply(struct ptlrpc_request *req) } /* Replay-enabled imports return commit-status information. */ - if (req->rq_repmsg->last_committed) + if (lustre_msg_get_last_committed(req->rq_repmsg)) imp->imp_peer_committed_transno = - req->rq_repmsg->last_committed; + lustre_msg_get_last_committed(req->rq_repmsg); ptlrpc_free_committed(imp); spin_unlock_irqrestore(&imp->imp_lock, flags); } @@ -686,7 +691,7 @@ static int ptlrpc_send_new_req(struct ptlrpc_request *req) DEBUG_REQ(D_HA, req, "req from PID %d waiting for recovery: " "(%s != %s)", - req->rq_reqmsg->status, + lustre_msg_get_status(req->rq_reqmsg) , ptlrpc_import_state_name(req->rq_send_state), ptlrpc_import_state_name(imp->imp_state)); LASSERT(list_empty (&req->rq_list)); @@ -708,13 +713,13 @@ static int ptlrpc_send_new_req(struct ptlrpc_request *req) list_add_tail(&req->rq_list, &imp->imp_sending_list); spin_unlock_irqrestore(&imp->imp_lock, flags); - req->rq_reqmsg->status = cfs_curproc_pid(); + lustre_msg_set_status(req->rq_reqmsg, cfs_curproc_pid()); CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:nid:opc" " %s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(), - imp->imp_obd->obd_uuid.uuid, req->rq_reqmsg->status, - req->rq_xid, + imp->imp_obd->obd_uuid.uuid, + lustre_msg_get_status(req->rq_reqmsg), req->rq_xid, libcfs_nid2str(imp->imp_connection->c_peer.nid), - req->rq_reqmsg->opc); + lustre_msg_get_opc(req->rq_reqmsg)); rc = ptl_send_rpc(req, 0); if (rc) { @@ -929,10 +934,10 @@ int ptlrpc_check_set(struct ptlrpc_request_set *set) CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:nid:" "opc %s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(), - imp->imp_obd->obd_uuid.uuid, req->rq_reqmsg->status, - req->rq_xid, + imp->imp_obd->obd_uuid.uuid, + lustre_msg_get_status(req->rq_reqmsg), req->rq_xid, libcfs_nid2str(imp->imp_connection->c_peer.nid), - req->rq_reqmsg->opc); + lustre_msg_get_opc(req->rq_reqmsg)); set->set_remaining--; @@ -985,7 +990,7 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req) RETURN(1); } - ptlrpc_fail_import(imp, req->rq_reqmsg->conn_cnt); + ptlrpc_fail_import(imp, lustre_msg_get_conn_cnt(req->rq_reqmsg)); RETURN(0); } @@ -1371,7 +1376,7 @@ void ptlrpc_resend_req(struct ptlrpc_request *req) unsigned long flags; DEBUG_REQ(D_HA, req, "going to resend"); - req->rq_reqmsg->handle.cookie = 0; + lustre_msg_set_handle(req->rq_reqmsg, &(struct lustre_handle){ 0 }); req->rq_status = -EAGAIN; spin_lock_irqsave (&req->rq_lock, flags); @@ -1492,14 +1497,14 @@ int ptlrpc_queue_wait(struct ptlrpc_request *req) atomic_inc(&imp->imp_inflight); /* for distributed debugging */ - req->rq_reqmsg->status = cfs_curproc_pid(); + lustre_msg_set_status(req->rq_reqmsg, cfs_curproc_pid()); LASSERT(imp->imp_obd != NULL); CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:nid:opc " "%s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(), imp->imp_obd->obd_uuid.uuid, - req->rq_reqmsg->status, req->rq_xid, + lustre_msg_get_status(req->rq_reqmsg), req->rq_xid, libcfs_nid2str(imp->imp_connection->c_peer.nid), - req->rq_reqmsg->opc); + lustre_msg_get_opc(req->rq_reqmsg)); /* Mark phase here for a little debug help */ req->rq_phase = RQ_PHASE_RPC; @@ -1594,9 +1599,9 @@ restart: CDEBUG(D_RPCTRACE, "Completed RPC pname:cluuid:pid:xid:nid:opc " "%s:%s:%d:"LPU64":%s:%d\n", cfs_curproc_comm(), imp->imp_obd->obd_uuid.uuid, - req->rq_reqmsg->status, req->rq_xid, + lustre_msg_get_status(req->rq_reqmsg), req->rq_xid, libcfs_nid2str(imp->imp_connection->c_peer.nid), - req->rq_reqmsg->opc); + lustre_msg_get_opc(req->rq_reqmsg)); spin_lock_irqsave(&imp->imp_lock, flags); list_del_init(&req->rq_list); @@ -1638,7 +1643,7 @@ restart: GOTO(out, rc = req->rq_status); } - rc = after_reply (req); + rc = after_reply(req); /* NB may return +ve success rc */ if (req->rq_resend) { spin_lock_irqsave(&imp->imp_lock, flags); @@ -1699,23 +1704,13 @@ static int ptlrpc_replay_interpret(struct ptlrpc_request *req, GOTO(out, rc = -ETIMEDOUT); } -#if SWAB_PARANOIA - /* Clear reply swab mask; this is a new reply in sender's byte order */ - req->rq_rep_swab_mask = 0; -#endif - LASSERT (req->rq_nob_received <= req->rq_replen); - rc = lustre_unpack_msg(req->rq_repmsg, req->rq_nob_received); - if (rc) { - DEBUG_REQ(D_ERROR, req, "unpack_rep failed: %d\n", rc); - GOTO(out, rc = -EPROTO); - } - - if (req->rq_repmsg->type == PTL_RPC_MSG_ERR && - req->rq_repmsg->status == -ENOTCONN) - GOTO(out, rc = req->rq_repmsg->status); + if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR && + lustre_msg_get_status(req->rq_repmsg) == -ENOTCONN) + GOTO(out, rc = lustre_msg_get_status(req->rq_repmsg)); /* The transno had better not change over replay. */ - LASSERT(req->rq_reqmsg->transno == req->rq_repmsg->transno); + LASSERT(lustre_msg_get_transno(req->rq_reqmsg) == + lustre_msg_get_transno(req->rq_repmsg)); DEBUG_REQ(D_HA, req, "got rep"); @@ -1723,12 +1718,14 @@ static int ptlrpc_replay_interpret(struct ptlrpc_request *req, if (req->rq_replay_cb) req->rq_replay_cb(req); - if (req->rq_replied && req->rq_repmsg->status != aa->praa_old_status) { + if (req->rq_replied && + lustre_msg_get_status(req->rq_repmsg) != aa->praa_old_status) { DEBUG_REQ(D_ERROR, req, "status %d, old was %d", - req->rq_repmsg->status, aa->praa_old_status); + lustre_msg_get_status(req->rq_repmsg), + aa->praa_old_status); } else { /* Put it back for re-replay. */ - req->rq_repmsg->status = aa->praa_old_status; + lustre_msg_set_status(req->rq_repmsg, aa->praa_old_status); } spin_lock_irqsave(&imp->imp_lock, flags); @@ -1768,7 +1765,7 @@ int ptlrpc_replay_req(struct ptlrpc_request *req) aa->praa_old_state = req->rq_send_state; req->rq_send_state = LUSTRE_IMP_REPLAY; req->rq_phase = RQ_PHASE_NEW; - aa->praa_old_status = req->rq_repmsg->status; + aa->praa_old_status = lustre_msg_get_status(req->rq_repmsg); req->rq_status = 0; req->rq_interpret_reply = ptlrpc_replay_interpret; diff --git a/lustre/ptlrpc/import.c b/lustre/ptlrpc/import.c index 8b89cd9..87ce4db 100644 --- a/lustre/ptlrpc/import.c +++ b/lustre/ptlrpc/import.c @@ -91,7 +91,8 @@ int ptlrpc_init_import(struct obd_import *imp) EXPORT_SYMBOL(ptlrpc_init_import); #define UUID_STR "_UUID" -static void deuuidify(char *uuid, const char *prefix, char **uuid_start, int *uuid_len) +static void deuuidify(char *uuid, const char *prefix, char **uuid_start, + int *uuid_len) { *uuid_start = !prefix || strncmp(uuid, prefix, strlen(prefix)) ? uuid : uuid + strlen(prefix); @@ -308,14 +309,16 @@ int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid) int rc; __u64 committed_before_reconnect = 0; struct ptlrpc_request *request; - int size[] = {sizeof(imp->imp_obd->u.cli.cl_target_uuid), - sizeof(obd->obd_uuid), - sizeof(imp->imp_dlm_handle), - sizeof(imp->imp_connect_data)}; - char *tmp[] = {obd2cli_tgt(imp->imp_obd), - obd->obd_uuid.uuid, - (char *)&imp->imp_dlm_handle, - (char *)&imp->imp_connect_data}; + int size[] = { sizeof(struct ptlrpc_body), + sizeof(imp->imp_obd->u.cli.cl_target_uuid), + sizeof(obd->obd_uuid), + sizeof(imp->imp_dlm_handle), + sizeof(imp->imp_connect_data) }; + char *tmp[] = { NULL, + obd2cli_tgt(imp->imp_obd), + obd->obd_uuid.uuid, + (char *)&imp->imp_dlm_handle, + (char *)&imp->imp_connect_data }; struct ptlrpc_connect_async_args *aa; unsigned long flags; @@ -378,18 +381,20 @@ int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid) GOTO(out, rc); request = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, imp->imp_connect_op, - 4, size, tmp); + 5, size, tmp); if (!request) GOTO(out, rc = -ENOMEM); #ifndef __KERNEL__ lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_LIBCLIENT); #endif + lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER); request->rq_send_state = LUSTRE_IMP_CONNECTING; /* Allow a slightly larger reply for future growth compatibility */ - size[0] = sizeof(struct obd_connect_data) + 16 * sizeof(__u64); - request->rq_replen = lustre_msg_size(1, size); + size[REPLY_REC_OFF] = sizeof(struct obd_connect_data) + + 16 * sizeof(__u64); + ptlrpc_req_set_repsize(request, 2, size); request->rq_interpret_reply = ptlrpc_connect_interpret; CLASSERT(sizeof (*aa) <= sizeof (request->rq_async_args)); @@ -483,7 +488,18 @@ static int ptlrpc_connect_interpret(struct ptlrpc_request *request, } else { imp->imp_replayable = 0; } - imp->imp_remote_handle = request->rq_repmsg->handle; + + if (msg_flags & MSG_CONNECT_NEXT_VER) { + imp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2; + CDEBUG(D_RPCTRACE, "connect to %s with lustre_msg_v2\n", + obd2cli_tgt(imp->imp_obd)); + } else { + CDEBUG(D_RPCTRACE, "connect to %s with lustre_msg_v1\n", + obd2cli_tgt(imp->imp_obd)); + } + + imp->imp_remote_handle = + *lustre_msg_get_handle(request->rq_repmsg); IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL); GOTO(finish, rc = 0); @@ -492,7 +508,7 @@ static int ptlrpc_connect_interpret(struct ptlrpc_request *request, /* Determine what recovery state to move the import to. */ if (MSG_CONNECT_RECONNECT & msg_flags) { memset(&old_hdl, 0, sizeof(old_hdl)); - if (!memcmp(&old_hdl, &request->rq_repmsg->handle, + if (!memcmp(&old_hdl, lustre_msg_get_handle(request->rq_repmsg), sizeof (old_hdl))) { CERROR("%s@%s didn't like our handle "LPX64 ", failed\n", obd2cli_tgt(imp->imp_obd), @@ -501,15 +517,18 @@ static int ptlrpc_connect_interpret(struct ptlrpc_request *request, GOTO(out, rc = -ENOTCONN); } - if (memcmp(&imp->imp_remote_handle, &request->rq_repmsg->handle, + if (memcmp(&imp->imp_remote_handle, + lustre_msg_get_handle(request->rq_repmsg), sizeof(imp->imp_remote_handle))) { CERROR("%s@%s changed handle from "LPX64" to "LPX64 "; copying, but this may foreshadow disaster\n", obd2cli_tgt(imp->imp_obd), imp->imp_connection->c_remote_uuid.uuid, imp->imp_remote_handle.cookie, - request->rq_repmsg->handle.cookie); - imp->imp_remote_handle = request->rq_repmsg->handle; + lustre_msg_get_handle(request->rq_repmsg)-> + cookie); + imp->imp_remote_handle = + *lustre_msg_get_handle(request->rq_repmsg); } else { CDEBUG(D_HA, "reconnected to %s@%s after partition\n", obd2cli_tgt(imp->imp_obd), @@ -529,11 +548,13 @@ static int ptlrpc_connect_interpret(struct ptlrpc_request *request, } } else if ((MSG_CONNECT_RECOVERING & msg_flags) && !imp->imp_invalid) { LASSERT(imp->imp_replayable); - imp->imp_remote_handle = request->rq_repmsg->handle; + imp->imp_remote_handle = + *lustre_msg_get_handle(request->rq_repmsg); imp->imp_last_replay_transno = 0; IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY); } else { - imp->imp_remote_handle = request->rq_repmsg->handle; + imp->imp_remote_handle = + *lustre_msg_get_handle(request->rq_repmsg); IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); } @@ -543,13 +564,14 @@ static int ptlrpc_connect_interpret(struct ptlrpc_request *request, "after reconnect. We should LBUG right here.\n"); } - if (request->rq_repmsg->last_committed < aa->pcaa_peer_committed) { + if (lustre_msg_get_last_committed(request->rq_repmsg) < + aa->pcaa_peer_committed) { CERROR("%s went back in time (transno "LPD64 " was previously committed, server now claims "LPD64 ")! See https://bugzilla.clusterfs.com/" "long_list.cgi?buglist=9646\n", obd2cli_tgt(imp->imp_obd), aa->pcaa_peer_committed, - request->rq_repmsg->last_committed); + lustre_msg_get_last_committed(request->rq_repmsg)); } finish: @@ -567,7 +589,7 @@ finish: struct obd_connect_data *ocd; struct obd_export *exp; - ocd = lustre_swab_repbuf(request, 0, + ocd = lustre_swab_repbuf(request, REPLY_REC_OFF, sizeof *ocd, lustre_swab_connect); if (ocd == NULL) { CERROR("Wrong connect data from server\n"); @@ -702,16 +724,15 @@ static int signal_completed_replay(struct obd_import *imp) LASSERT(atomic_read(&imp->imp_replay_inflight) == 0); atomic_inc(&imp->imp_replay_inflight); - req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING, - 0, NULL, NULL); + req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING, 1, NULL, NULL); if (!req) { atomic_dec(&imp->imp_replay_inflight); RETURN(-ENOMEM); } - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); req->rq_send_state = LUSTRE_IMP_REPLAY_WAIT; - req->rq_reqmsg->flags |= MSG_LAST_REPLAY; + lustre_msg_add_flags(req->rq_reqmsg, MSG_LAST_REPLAY); req->rq_timeout *= 3; req->rq_interpret_reply = completed_replay_interpret; @@ -839,9 +860,8 @@ static int back_to_sleep(void *unused) int ptlrpc_disconnect_import(struct obd_import *imp) { - struct ptlrpc_request *request; - int rq_opc; - int rc = 0; + struct ptlrpc_request *req; + int rq_opc, rc = 0; unsigned long flags; ENTRY; @@ -857,7 +877,9 @@ int ptlrpc_disconnect_import(struct obd_import *imp) if (ptlrpc_import_in_recovery(imp)) { struct l_wait_info lwi; - lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(cfs_time_seconds(obd_timeout)), + cfs_duration_t timeout = cfs_time_seconds(obd_timeout); + + lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), back_to_sleep, NULL, NULL); rc = l_wait_event(imp->imp_recovery_waitq, !ptlrpc_import_in_recovery(imp), &lwi); @@ -870,19 +892,18 @@ int ptlrpc_disconnect_import(struct obd_import *imp) spin_unlock_irqrestore(&imp->imp_lock, flags); - request = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, rq_opc, - 0, NULL, NULL); - if (request) { + req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, rq_opc, 1, NULL, NULL); + if (req) { /* We are disconnecting, do not retry a failed DISCONNECT rpc if * it fails. We can get through the above with a down server * if the client doesn't know the server is gone yet. */ - request->rq_no_resend = 1; - request->rq_timeout = 5; + req->rq_no_resend = 1; + req->rq_timeout = 5; IMPORT_SET_STATE(imp, LUSTRE_IMP_CONNECTING); - request->rq_send_state = LUSTRE_IMP_CONNECTING; - request->rq_replen = lustre_msg_size(0, NULL); - rc = ptlrpc_queue_wait(request); - ptlrpc_req_finished(request); + req->rq_send_state = LUSTRE_IMP_CONNECTING; + ptlrpc_req_set_repsize(req, 1, NULL); + rc = ptlrpc_queue_wait(req); + ptlrpc_req_finished(req); } spin_lock_irqsave(&imp->imp_lock, flags); diff --git a/lustre/ptlrpc/llog_client.c b/lustre/ptlrpc/llog_client.c index bcab551..27578a4 100644 --- a/lustre/ptlrpc/llog_client.c +++ b/lustre/ptlrpc/llog_client.c @@ -53,10 +53,9 @@ static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res, struct llogd_body *body; struct llog_handle *handle; struct ptlrpc_request *req = NULL; - int size[2] = {sizeof(req_body)}; - char *tmp[2] = {(char*) &req_body}; - int bufcount = 1; - int repsize[] = {sizeof (req_body)}; + int size[3] = { sizeof(struct ptlrpc_body), sizeof(req_body) }; + char *bufs[3] = { NULL, (char*)&req_body }; + int bufcount = 2; int rc; ENTRY; @@ -81,21 +80,21 @@ static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res, if (name) { size[bufcount] = strlen(name) + 1; - tmp[bufcount] = name; + bufs[bufcount] = name; bufcount++; } req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION, - LLOG_ORIGIN_HANDLE_CREATE, bufcount, size, tmp); + LLOG_ORIGIN_HANDLE_CREATE, bufcount, size, bufs); if (!req) GOTO(err_free, rc = -ENOMEM); - req->rq_replen = lustre_msg_size(1, repsize); + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); if (rc) GOTO(err_free, rc); - body = lustre_swab_repbuf(req, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_llogd_body); if (body == NULL) { CERROR ("Can't unpack llogd_body\n"); @@ -120,21 +119,20 @@ static int llog_client_destroy(struct llog_handle *loghandle) struct obd_import *imp = loghandle->lgh_ctxt->loc_imp; struct ptlrpc_request *req = NULL; struct llogd_body *body; - int size = sizeof(*body); - int repsize[2] = {sizeof (*body)}; + int size[] = { sizeof(struct ptlrpc_body), sizeof(*body) }; int rc; ENTRY; req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION, - LLOG_ORIGIN_HANDLE_DESTROY, 1, &size, NULL); + LLOG_ORIGIN_HANDLE_DESTROY, 2, size, NULL); if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); body->lgd_logid = loghandle->lgh_id; body->lgd_llh_flags = loghandle->lgh_hdr->llh_flags; - req->rq_replen = lustre_msg_size(1, repsize); + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); ptlrpc_req_finished(req); @@ -150,17 +148,16 @@ static int llog_client_next_block(struct llog_handle *loghandle, struct ptlrpc_request *req = NULL; struct llogd_body *body; void * ptr; - int size = sizeof(*body); - int repsize[2] = {sizeof (*body)}; + int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) }; int rc; ENTRY; req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION, - LLOG_ORIGIN_HANDLE_NEXT_BLOCK, 1,&size,NULL); + LLOG_ORIGIN_HANDLE_NEXT_BLOCK, 2, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); body->lgd_logid = loghandle->lgh_id; body->lgd_ctxt_idx = loghandle->lgh_ctxt->loc_idx - 1; body->lgd_llh_flags = loghandle->lgh_hdr->llh_flags; @@ -168,14 +165,14 @@ static int llog_client_next_block(struct llog_handle *loghandle, body->lgd_saved_index = *cur_idx; body->lgd_len = len; body->lgd_cur_offset = *cur_offset; - repsize[1] = len; - req->rq_replen = lustre_msg_size(2, repsize); + size[REPLY_REC_OFF + 1] = len; + ptlrpc_req_set_repsize(req, 3, size); rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - body = lustre_swab_repbuf(req, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_llogd_body); if (body == NULL) { CERROR ("Can't unpack llogd_body\n"); @@ -183,7 +180,7 @@ static int llog_client_next_block(struct llog_handle *loghandle, } /* The log records are swabbed as they are processed */ - ptr = lustre_msg_buf(req->rq_repmsg, 1, len); + ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, len); if (ptr == NULL) { CERROR ("Can't unpack bitmap\n"); GOTO(out, rc =-EFAULT); @@ -207,37 +204,36 @@ static int llog_client_prev_block(struct llog_handle *loghandle, struct ptlrpc_request *req = NULL; struct llogd_body *body; void * ptr; - int size = sizeof(*body); - int repsize[2] = {sizeof (*body)}; + int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) }; int rc; ENTRY; req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION, - LLOG_ORIGIN_HANDLE_PREV_BLOCK, 1,&size,NULL); + LLOG_ORIGIN_HANDLE_PREV_BLOCK, 2, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); body->lgd_logid = loghandle->lgh_id; body->lgd_ctxt_idx = loghandle->lgh_ctxt->loc_idx - 1; body->lgd_llh_flags = loghandle->lgh_hdr->llh_flags; body->lgd_index = prev_idx; body->lgd_len = len; - repsize[1] = len; - req->rq_replen = lustre_msg_size(2, repsize); + size[REPLY_REC_OFF + 1] = len; + ptlrpc_req_set_repsize(req, 3, size); rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - body = lustre_swab_repbuf(req, 0, sizeof(*body), + body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body), lustre_swab_llogd_body); if (body == NULL) { CERROR ("Can't unpack llogd_body\n"); GOTO(out, rc =-EFAULT); } - ptr = lustre_msg_buf(req->rq_repmsg, 1, len); + ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, len); if (ptr == NULL) { CERROR ("Can't unpack bitmap\n"); GOTO(out, rc =-EFAULT); @@ -258,27 +254,28 @@ static int llog_client_read_header(struct llog_handle *handle) struct llogd_body *body; struct llog_log_hdr *hdr; struct llog_rec_hdr *llh_hdr; - int size = sizeof(*body); - int repsize = sizeof (*hdr); + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int repsize[2] = { sizeof(struct ptlrpc_body), sizeof(*hdr) }; int rc; ENTRY; req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION, - LLOG_ORIGIN_HANDLE_READ_HEADER, 1, &size, NULL); + LLOG_ORIGIN_HANDLE_READ_HEADER, 2, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); body->lgd_logid = handle->lgh_id; body->lgd_ctxt_idx = handle->lgh_ctxt->loc_idx - 1; body->lgd_llh_flags = handle->lgh_hdr->llh_flags; - req->rq_replen = lustre_msg_size(1, &repsize); + ptlrpc_req_set_repsize(req, 2, repsize); rc = ptlrpc_queue_wait(req); if (rc) GOTO(out, rc); - hdr = lustre_swab_repbuf(req, 0, sizeof(*hdr), lustre_swab_llog_hdr); + hdr = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*hdr), + lustre_swab_llog_hdr); if (hdr == NULL) { CERROR ("Can't unpack llog_hdr\n"); GOTO(out, rc =-EFAULT); diff --git a/lustre/ptlrpc/llog_net.c b/lustre/ptlrpc/llog_net.c index 735ed31..8702071 100644 --- a/lustre/ptlrpc/llog_net.c +++ b/lustre/ptlrpc/llog_net.c @@ -55,7 +55,8 @@ int llog_origin_connect(struct llog_ctxt *ctxt, int count, struct obd_import *imp; struct ptlrpc_request *request; struct llogd_conn_body *req_body; - int size = sizeof(struct llogd_conn_body); + int size[2] = { sizeof(struct ptlrpc_body), + sizeof(struct llogd_conn_body) }; int rc; ENTRY; @@ -83,16 +84,17 @@ int llog_origin_connect(struct llog_ctxt *ctxt, int count, imp = ctxt->loc_imp; request = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION, - LLOG_ORIGIN_CONNECT, 1, &size, NULL); + LLOG_ORIGIN_CONNECT, 2, size, NULL); if (!request) RETURN(-ENOMEM); - req_body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*req_body)); + req_body = lustre_msg_buf(request->rq_reqmsg, REQ_REC_OFF, + sizeof(*req_body)); req_body->lgdc_gen = ctxt->loc_gen; req_body->lgdc_logid = ctxt->loc_handle->lgh_id; req_body->lgdc_ctxt_idx = ctxt->loc_idx + 1; - request->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(request, 1, NULL); rc = ptlrpc_queue_wait(request); ptlrpc_req_finished(request); @@ -109,7 +111,8 @@ int llog_handle_connect(struct ptlrpc_request *req) int rc; ENTRY; - req_body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*req_body)); + req_body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, + sizeof(*req_body)); ctxt = llog_get_context(obd, req_body->lgdc_ctxt_idx); rc = llog_connect(ctxt, 1, &req_body->lgdc_logid, diff --git a/lustre/ptlrpc/llog_server.c b/lustre/ptlrpc/llog_server.c index e536c82..d4bd482 100644 --- a/lustre/ptlrpc/llog_server.c +++ b/lustre/ptlrpc/llog_server.c @@ -55,11 +55,11 @@ int llog_origin_handle_create(struct ptlrpc_request *req) struct llog_logid *logid = NULL; struct llog_ctxt *ctxt; char * name = NULL; - int size = sizeof (*body); + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; int rc, rc2; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), lustre_swab_llogd_body); if (body == NULL) { CERROR ("Can't unpack llogd_body\n"); @@ -69,8 +69,8 @@ int llog_origin_handle_create(struct ptlrpc_request *req) if (body->lgd_logid.lgl_oid > 0) logid = &body->lgd_logid; - if (req->rq_reqmsg->bufcount > 1) { - name = lustre_msg_string(req->rq_reqmsg, 1, 0); + if (lustre_msg_bufcount(req->rq_reqmsg) > 2) { + name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1, 0); if (name == NULL) { CERROR("Can't unpack name\n"); GOTO(out, rc = -EFAULT); @@ -88,11 +88,11 @@ int llog_origin_handle_create(struct ptlrpc_request *req) if (rc) GOTO(out_pop, rc); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) GOTO(out_close, rc = -ENOMEM); - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body)); body->lgd_logid = loghandle->lgh_id; out_close: @@ -115,12 +115,12 @@ int llog_origin_handle_destroy(struct ptlrpc_request *req) struct lvfs_run_ctxt saved; struct llog_logid *logid = NULL; struct llog_ctxt *ctxt; - int size = sizeof (*body); + int size[] = { sizeof(struct ptlrpc_body), sizeof(*body) }; int rc; __u32 flags; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), lustre_swab_llogd_body); if (body == NULL) { CERROR ("Can't unpack llogd_body\n"); @@ -140,11 +140,11 @@ int llog_origin_handle_destroy(struct ptlrpc_request *req) if (rc) GOTO(out_pop, rc); - rc = lustre_pack_reply(req, 1, &size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) GOTO(out_close, rc = -ENOMEM); - body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); + body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (*body)); body->lgd_logid = loghandle->lgh_id; flags = body->lgd_llh_flags; rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL); @@ -176,12 +176,13 @@ int llog_origin_handle_next_block(struct ptlrpc_request *req) __u32 flags; __u8 *buf; void * ptr; - int size[] = {sizeof (*body), - LLOG_CHUNK_SIZE}; + int size[3] = { sizeof(struct ptlrpc_body), + sizeof(*body), + LLOG_CHUNK_SIZE }; int rc, rc2; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), lustre_swab_llogd_body); if (body == NULL) { CERROR ("Can't unpack llogd_body\n"); @@ -215,14 +216,14 @@ int llog_origin_handle_next_block(struct ptlrpc_request *req) GOTO(out_close, rc); - rc = lustre_pack_reply(req, 2, size, NULL); + rc = lustre_pack_reply(req, 3, size, NULL); if (rc) GOTO(out_close, rc = -ENOMEM); - ptr = lustre_msg_buf(req->rq_repmsg, 0, sizeof (body)); + ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (body)); memcpy(ptr, body, sizeof(*body)); - ptr = lustre_msg_buf(req->rq_repmsg, 1, LLOG_CHUNK_SIZE); + ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF+1, LLOG_CHUNK_SIZE); memcpy(ptr, buf, LLOG_CHUNK_SIZE); out_close: @@ -250,12 +251,13 @@ int llog_origin_handle_prev_block(struct ptlrpc_request *req) __u32 flags; __u8 *buf; void * ptr; - int size[] = {sizeof (*body), - LLOG_CHUNK_SIZE}; + int size[] = { sizeof(struct ptlrpc_body), + sizeof(*body), + LLOG_CHUNK_SIZE }; int rc, rc2; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), lustre_swab_llogd_body); if (body == NULL) { CERROR ("Can't unpack llogd_body\n"); @@ -287,14 +289,14 @@ int llog_origin_handle_prev_block(struct ptlrpc_request *req) GOTO(out_close, rc); - rc = lustre_pack_reply(req, 2, size, NULL); + rc = lustre_pack_reply(req, 3, size, NULL); if (rc) GOTO(out_close, rc = -ENOMEM); - ptr = lustre_msg_buf(req->rq_repmsg, 0, sizeof (body)); + ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(body)); memcpy(ptr, body, sizeof(*body)); - ptr = lustre_msg_buf(req->rq_repmsg, 1, LLOG_CHUNK_SIZE); + ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF+1, LLOG_CHUNK_SIZE); memcpy(ptr, buf, LLOG_CHUNK_SIZE); out_close: @@ -320,11 +322,11 @@ int llog_origin_handle_read_header(struct ptlrpc_request *req) struct lvfs_run_ctxt saved; struct llog_ctxt *ctxt; __u32 flags; - int size[] = {sizeof (*hdr)}; + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*hdr) }; int rc, rc2; ENTRY; - body = lustre_swab_reqbuf(req, 0, sizeof(*body), + body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body), lustre_swab_llogd_body); if (body == NULL) { CERROR ("Can't unpack llogd_body\n"); @@ -347,11 +349,11 @@ int llog_origin_handle_read_header(struct ptlrpc_request *req) if (rc) GOTO(out_close, rc); - rc = lustre_pack_reply(req, 1, size, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) GOTO(out_close, rc = -ENOMEM); - hdr = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*hdr)); + hdr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*hdr)); memcpy(hdr, loghandle->lgh_hdr, sizeof(*hdr)); out_close: @@ -388,8 +390,10 @@ int llog_origin_handle_cancel(struct ptlrpc_request *req) void *handle; ENTRY; - logcookies = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*logcookies)); - num_cookies = req->rq_reqmsg->buflens[0]/sizeof(*logcookies); + logcookies = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, + sizeof(*logcookies)); + num_cookies = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF) / + sizeof(*logcookies); if (logcookies == NULL || num_cookies == 0) { DEBUG_REQ(D_HA, req, "no cookies sent"); RETURN(-EFAULT); @@ -632,16 +636,18 @@ int llog_catinfo(struct ptlrpc_request *req) char *keyword; char *buf, *reply; int rc, buf_len = LLOG_CHUNK_SIZE; + int size[2] = { sizeof(struct ptlrpc_body), buf_len }; OBD_ALLOC(buf, buf_len); if (buf == NULL) return -ENOMEM; memset(buf, 0, buf_len); - keyword = lustre_msg_string(req->rq_reqmsg, 0, 0); + keyword = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF, 0); if (strcmp(keyword, "config") == 0) { - char *client = lustre_msg_string(req->rq_reqmsg, 1, 0); + char *client = lustre_msg_string(req->rq_reqmsg, + REQ_REC_OFF + 1, 0); rc = llog_catinfo_config(obd, buf, buf_len, client); } else if (strcmp(keyword, "deletions") == 0) { rc = llog_catinfo_deletions(obd, buf, buf_len); @@ -649,11 +655,11 @@ int llog_catinfo(struct ptlrpc_request *req) rc = -EOPNOTSUPP; } - rc = lustre_pack_reply(req, 1, &buf_len, NULL); + rc = lustre_pack_reply(req, 2, size, NULL); if (rc) GOTO(out_free, rc = -ENOMEM); - reply = lustre_msg_buf(req->rq_repmsg, 0, buf_len); + reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, buf_len); if (strlen(buf) == 0) sprintf(buf, "%s", "No log informations\n"); memcpy(reply, buf, buf_len); diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index fde851b..40c6d78 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -419,7 +419,7 @@ EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd); void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req) { struct lprocfs_stats *svc_stats; - int opc = opcode_offset(req->rq_reqmsg->opc); + int opc = opcode_offset(lustre_msg_get_opc(req->rq_reqmsg)); svc_stats = req->rq_import->imp_obd->obd_svc_stats; if (svc_stats == NULL || opc <= 0) @@ -477,11 +477,11 @@ int lprocfs_wr_ping(struct file *file, const char *buffer, ENTRY; req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_OBD_VERSION, - OBD_PING, 0, NULL, NULL); + OBD_PING, 1, NULL, NULL); if (req == NULL) RETURN(-ENOMEM); - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); req->rq_send_state = LUSTRE_IMP_FULL; req->rq_no_resend = 1; diff --git a/lustre/ptlrpc/niobuf.c b/lustre/ptlrpc/niobuf.c index b05c5a3..040854c 100644 --- a/lustre/ptlrpc/niobuf.c +++ b/lustre/ptlrpc/niobuf.c @@ -318,7 +318,7 @@ int ptlrpc_send_reply (struct ptlrpc_request *req, int may_be_difficult) LASSERT (rs != NULL); LASSERT (req->rq_repmsg != NULL); LASSERT (may_be_difficult || !rs->rs_difficult); - LASSERT (req->rq_repmsg == &rs->rs_msg); + LASSERT (req->rq_repmsg == rs->rs_msg); LASSERT (rs->rs_cb_id.cbid_fn == reply_out_callback); LASSERT (rs->rs_cb_id.cbid_arg == rs); LASSERT (req->rq_repmsg != NULL); @@ -335,9 +335,9 @@ int ptlrpc_send_reply (struct ptlrpc_request *req, int may_be_difficult) if (req->rq_type != PTL_RPC_MSG_ERR) req->rq_type = PTL_RPC_MSG_REPLY; - req->rq_repmsg->type = req->rq_type; - req->rq_repmsg->status = req->rq_status; - req->rq_repmsg->opc = req->rq_reqmsg->opc; + lustre_msg_set_type(req->rq_repmsg, req->rq_type); + lustre_msg_set_status(req->rq_repmsg, req->rq_status); + lustre_msg_set_opc(req->rq_repmsg, lustre_msg_get_opc(req->rq_reqmsg)); if (req->rq_export == NULL || req->rq_export->exp_connection == NULL) conn = ptlrpc_get_connection(req->rq_peer, req->rq_self, NULL); @@ -374,14 +374,14 @@ int ptlrpc_error(struct ptlrpc_request *req) ENTRY; if (!req->rq_repmsg) { - rc = lustre_pack_reply(req, 0, NULL, NULL); + rc = lustre_pack_reply(req, 1, NULL, NULL); if (rc) RETURN(rc); } req->rq_type = PTL_RPC_MSG_ERR; - rc = ptlrpc_send_reply (req, 0); + rc = ptlrpc_send_reply(req, 0); RETURN(rc); } @@ -420,9 +420,11 @@ int ptl_send_rpc(struct ptlrpc_request *request, int noreply) RETURN(rc); } - request->rq_reqmsg->handle = request->rq_import->imp_remote_handle; - request->rq_reqmsg->type = PTL_RPC_MSG_REQUEST; - request->rq_reqmsg->conn_cnt = request->rq_import->imp_conn_cnt; + lustre_msg_set_handle(request->rq_reqmsg, + &request->rq_import->imp_remote_handle); + lustre_msg_set_type(request->rq_reqmsg, PTL_RPC_MSG_REQUEST); + lustre_msg_set_conn_cnt(request->rq_reqmsg, + request->rq_import->imp_conn_cnt); if (!noreply) { LASSERT (request->rq_replen != 0); @@ -500,7 +502,7 @@ int ptl_send_rpc(struct ptlrpc_request *request, int noreply) /* drop request_out_callback refs, we couldn't start the send */ atomic_dec(&request->rq_import->imp_inflight); - ptlrpc_req_finished (request); + ptlrpc_req_finished(request); if (noreply) RETURN(rc); diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index 712dd10..14483fa 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -37,52 +37,160 @@ #include #include +#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2,0,0,0) +#error "lustre_msg_v1 has been deprecated since 1.6.0, please remove it" +#elif LUSTRE_VERSION_CODE > OBD_OCD_VERSION(1,6,7,0) +#warning "lustre_msg_v1 has been deprecated since 1.6.0, consider removing it" +#endif -#define HDR_SIZE(count) \ - size_round(offsetof (struct lustre_msg, buflens[(count)])) +static inline int lustre_msg_hdr_size_v1(int count) +{ + return size_round(offsetof(struct lustre_msg_v1, lm_buflens[count])); +} + +static inline int lustre_msg_hdr_size_v2(int count) +{ + return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count])); +} int lustre_msg_swabbed(struct lustre_msg *msg) { - return (msg->magic == __swab32(PTLRPC_MSG_MAGIC)); + return (msg->lm_magic == LUSTRE_MSG_MAGIC_V1_SWABBED) || + (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED); } -int lustre_msg_check_version(struct lustre_msg *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); + if (lustre_msg_swabbed(msg)) - return (__swab32(msg->version) & LUSTRE_VERSION_MASK) != version; + return (__swab32(ver) & LUSTRE_VERSION_MASK) != version; + + return (ver & LUSTRE_VERSION_MASK) != version; +} + +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: + return 0; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: + return lustre_msg_check_version_v2(msg, version); + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return -EINVAL; + } +} + +static inline int lustre_msg_size_v1(int count, int *lengths) +{ + int size; + int i; + + LASSERT(count >= 0); + size = lustre_msg_hdr_size_v1(count); + for (i = 0; i < count; i++) + size += size_round(lengths[i]); + + return size; +} + +static inline int lustre_msg_size_v2(int count, int *lengths) +{ + int size; + int i; + + size = lustre_msg_hdr_size_v2(count); + for (i = 0; i < count; i++) + size += size_round(lengths[i]); + + return size; +} - return (msg->version & LUSTRE_VERSION_MASK) != version; +/* This returns the size of the buffer that is required to hold a lustre_msg + * with the given sub-buffer lengths. */ +int lustre_msg_size(__u32 magic, int count, int *lens) +{ + int size[] = { sizeof(struct ptlrpc_body) }; + + if (!lens) { + LASSERT(count == 1); + lens = size; + } + + LASSERT(count > 0); + LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body)); + + switch (magic) { + case LUSTRE_MSG_MAGIC_V1: + return lustre_msg_size_v1(count - 1, lens + 1); + case LUSTRE_MSG_MAGIC_V2: + return lustre_msg_size_v2(count, lens); + default: + LASSERTF(0, "incorrect message magic: %08x\n", magic); + return -EINVAL; + } +} + +static void +lustre_init_msg_v1(void *m, int count, int *lens, char **bufs) +{ + struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m; + char *ptr; + int i; + + LASSERT(count >= 0); + msg->lm_magic = LUSTRE_MSG_MAGIC_V1; + msg->lm_version = PTLRPC_MSG_VERSION; + msg->lm_bufcount = count; + + for (i = 0; i < count; i++) + msg->lm_buflens[i] = lens[i]; + + if (bufs == NULL) + return; + + ptr = (char *)msg + lustre_msg_hdr_size_v1(count); + for (i = 0; i < count; i++) { + char *tmp = bufs[i]; + LOGL(tmp, lens[i], ptr); + } } static void -lustre_init_msg (struct lustre_msg *msg, int count, int *lens, char **bufs) +lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens, char **bufs) { char *ptr; - int i; + int i; + + msg->lm_bufcount = count; + /* XXX: lm_secflvr uninitialized here */ + msg->lm_magic = LUSTRE_MSG_MAGIC_V2; - msg->magic = PTLRPC_MSG_MAGIC; - msg->version = PTLRPC_MSG_VERSION; - msg->bufcount = count; for (i = 0; i < count; i++) - msg->buflens[i] = lens[i]; + msg->lm_buflens[i] = lens[i]; if (bufs == NULL) return; - ptr = (char *)msg + HDR_SIZE(count); + ptr = (char *)msg + lustre_msg_hdr_size_v2(count); for (i = 0; i < count; i++) { char *tmp = bufs[i]; LOGL(tmp, lens[i], ptr); } } -int lustre_pack_request (struct ptlrpc_request *req, - int count, int *lens, char **bufs) +static int lustre_pack_request_v1(struct ptlrpc_request *req, + int count, int *lens, char **bufs) { int reqlen; ENTRY; - reqlen = lustre_msg_size (count, lens); + reqlen = lustre_msg_size_v1(count, lens); + /* See if we got it from prealloc pool */ if (req->rq_reqmsg) { /* Cannot return error here, that would create @@ -99,12 +207,70 @@ int lustre_pack_request (struct ptlrpc_request *req, if (req->rq_reqmsg == NULL) RETURN(-ENOMEM); } + req->rq_reqlen = reqlen; - lustre_init_msg (req->rq_reqmsg, count, lens, bufs); + lustre_init_msg_v1(req->rq_reqmsg, count, lens, bufs); RETURN (0); } +static int lustre_pack_request_v2(struct ptlrpc_request *req, + int count, int *lens, char **bufs) +{ + int reqlen; + ENTRY; + + reqlen = lustre_msg_size_v2(count, lens); + + /* See if we got it from prealloc pool */ + if (req->rq_reqmsg) { + /* Cannot return error here, that would create + infinite loop in ptlrpc_prep_req_pool */ + /* In this case ptlrpc_prep_req_from_pool sets req->rq_reqlen + to maximum size that would fit into this preallocated + request */ + LASSERTF(req->rq_reqlen >= reqlen, "req->rq_reqlen %d, " + "reqlen %d\n",req->rq_reqlen, + reqlen); + memset(req->rq_reqmsg, 0, reqlen); + } else { + OBD_ALLOC(req->rq_reqmsg, reqlen); + if (req->rq_reqmsg == NULL) + RETURN(-ENOMEM); + } + + req->rq_reqlen = reqlen; + + lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs); + lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION); + RETURN(0); +} + +int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count, + int *lens, char **bufs) +{ + int size[] = { sizeof(struct ptlrpc_body) }; + + if (!lens) { + LASSERT(count == 1); + lens = size; + } + + LASSERT(count > 0); + LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body)); + + switch (magic) { + case LUSTRE_MSG_MAGIC_V1: + return lustre_pack_request_v1(req, count - 1, lens + 1, + bufs ? bufs + 1 : NULL); + case LUSTRE_MSG_MAGIC_V2: + return lustre_pack_request_v2(req, count, lens, bufs); + default: + LASSERTF(0, "incorrect message magic: %08x\n", magic); + return -EINVAL; + } +} + #if RS_DEBUG CFS_LIST_HEAD(ptlrpc_rs_debug_lru); spinlock_t ptlrpc_rs_debug_lock; @@ -166,9 +332,8 @@ out: return rs; } - -int lustre_pack_reply (struct ptlrpc_request *req, - int count, int *lens, char **bufs) +static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count, + int *lens, char **bufs) { struct ptlrpc_reply_state *rs; int msg_len; @@ -177,9 +342,9 @@ int lustre_pack_reply (struct ptlrpc_request *req, LASSERT (req->rq_reply_state == NULL); - msg_len = lustre_msg_size (count, lens); - size = offsetof (struct ptlrpc_reply_state, rs_msg) + msg_len; - OBD_ALLOC (rs, size); + msg_len = lustre_msg_size_v1(count, lens); + size = sizeof(struct ptlrpc_reply_state) + msg_len; + OBD_ALLOC(rs, size); if (unlikely(rs == NULL)) { rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service, size); if (!rs) @@ -192,71 +357,267 @@ int lustre_pack_reply (struct ptlrpc_request *req, rs->rs_size = size; CFS_INIT_LIST_HEAD(&rs->rs_exp_list); CFS_INIT_LIST_HEAD(&rs->rs_obd_list); + rs->rs_msg = (struct lustre_msg *)(rs + 1); req->rq_replen = msg_len; req->rq_reply_state = rs; - req->rq_repmsg = &rs->rs_msg; - lustre_init_msg (&rs->rs_msg, count, lens, bufs); + req->rq_repmsg = rs->rs_msg; + lustre_init_msg_v1(rs->rs_msg, count, lens, bufs); PTLRPC_RS_DEBUG_LRU_ADD(rs); RETURN (0); } -/* - * shrink @segment to size @newlen. if @move_data is non-zero, we also move - * data forward from @segment + 1. - * - * if @newlen == 0, we remove the segment completely, but we still keep the - * totally bufcount the same to save possible data moving. this will leave a - * unused segment with size 0 at the tail, but that's ok. - * - * CAUTION: - * + if any buffers higher than @segment has been filled in, must call shrink - * with non-zero @move_data. - * + caller should NOT keep pointers to msg buffers which higher than @segment - * after call shrink. - */ -void lustre_shrink_reply(struct ptlrpc_request *req, - int segment, unsigned int newlen, int move_data) +static int lustre_pack_reply_v2(struct ptlrpc_request *req, int count, + int *lens, char **bufs) { - struct lustre_msg *msg = req->rq_repmsg; - char *tail = NULL, *newpos; - int tail_len = 0, n; + struct ptlrpc_reply_state *rs; + int msg_len; + int size; + ENTRY; + + LASSERT(req->rq_reply_state == NULL); + + msg_len = lustre_msg_size_v2(count, lens); + size = sizeof(struct ptlrpc_reply_state) + msg_len; + OBD_ALLOC(rs, size); + if (unlikely(rs == NULL)) { + rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service, size); + if (!rs) + RETURN (-ENOMEM); + } + atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */ + rs->rs_cb_id.cbid_fn = reply_out_callback; + rs->rs_cb_id.cbid_arg = rs; + rs->rs_service = req->rq_rqbd->rqbd_service; + rs->rs_size = size; + CFS_INIT_LIST_HEAD(&rs->rs_exp_list); + CFS_INIT_LIST_HEAD(&rs->rs_obd_list); + rs->rs_msg = (struct lustre_msg *)(rs + 1); + + req->rq_replen = msg_len; + req->rq_reply_state = rs; + req->rq_repmsg = rs->rs_msg; + lustre_init_msg_v2(rs->rs_msg, count, lens, bufs); + lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION); + + PTLRPC_RS_DEBUG_LRU_ADD(rs); + + RETURN(0); +} + +int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens, + char **bufs) +{ + int size[] = { sizeof(struct ptlrpc_body) }; + + if (!lens) { + LASSERT(count == 1); + lens = size; + } + + LASSERT(count > 0); + LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body)); + + switch (req->rq_reqmsg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return lustre_pack_reply_v1(req, count - 1, lens + 1, + bufs ? bufs + 1 : NULL); + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: + return lustre_pack_reply_v2(req, count, lens, bufs); + default: + LASSERTF(0, "incorrect message magic: %08x\n", + req->rq_reqmsg->lm_magic); + return -EINVAL; + } +} + +void *lustre_msg_buf_v1(void *msg, int n, int min_size) +{ + struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg; + int i, offset, buflen, bufcount; + + LASSERT(m != NULL); + LASSERT(n >= 0); + + bufcount = m->lm_bufcount; + if (n >= bufcount) { + CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n", + m, n, bufcount); + return NULL; + } + + buflen = m->lm_buflens[n]; + if (buflen < min_size) { + CERROR("msg %p buffer[%d] size %d too small (required %d)\n", + m, n, buflen, min_size); + LBUG(); + return NULL; + } + + offset = lustre_msg_hdr_size_v1(bufcount); + for (i = 0; i < n; i++) + offset += size_round(m->lm_buflens[i]); + + return (char *)m + offset; +} + +void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size) +{ + int i, offset, buflen, bufcount; + + LASSERT(m != NULL); + LASSERT(n >= 0); + + bufcount = m->lm_bufcount; + if (n >= bufcount) { + CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n", + m, n, bufcount); + return NULL; + } + + buflen = m->lm_buflens[n]; + if (buflen < min_size) { + CERROR("msg %p buffer[%d] size %d too small (required %d)\n", + m, n, buflen, min_size); + return NULL; + } + + offset = lustre_msg_hdr_size_v2(bufcount); + for (i = 0; i < n; i++) + offset += size_round(m->lm_buflens[i]); + + return (char *)m + offset; +} + +void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size) +{ + switch (m->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return lustre_msg_buf_v1(m, n - 1, min_size); + 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\n", m->lm_magic); + return NULL; + } +} + +void lustre_shrink_reply_v1(struct ptlrpc_request *req, int segment, + unsigned int newlen, int move_data) +{ + struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)req->rq_repmsg; + char *tail = NULL, *newpos; + int tail_len = 0, n; LASSERT(req->rq_reply_state); LASSERT(msg); - LASSERT(msg->bufcount > segment); - LASSERT(msg->buflens[segment] >= newlen); + LASSERT(segment >= 0); + LASSERT(msg->lm_bufcount > segment); + LASSERT(msg->lm_buflens[segment] >= newlen); - if (msg->buflens[segment] == newlen) + if (msg->lm_buflens[segment] == newlen) return; - if (move_data && msg->bufcount > segment + 1) { - tail = lustre_msg_buf(msg, segment + 1, 0); - for (n = segment + 1; n < msg->bufcount; n++) - tail_len += size_round(msg->buflens[n]); + if (move_data && msg->lm_bufcount > segment + 1) { + tail = lustre_msg_buf_v1(msg, segment + 1, 0); + for (n = segment + 1; n < msg->lm_bufcount; n++) + tail_len += size_round(msg->lm_buflens[n]); } - msg->buflens[segment] = newlen; + msg->lm_buflens[segment] = newlen; if (tail && tail_len) { - newpos = lustre_msg_buf(msg, segment + 1, 0); + newpos = lustre_msg_buf_v1(msg, segment + 1, 0); LASSERT(newpos <= tail); if (newpos != tail) memcpy(newpos, tail, tail_len); } - if (newlen == 0 && msg->bufcount > segment + 1) { - memmove(&msg->buflens[segment], &msg->buflens[segment + 1], - (msg->bufcount - segment - 1) * sizeof(__u32)); - msg->buflens[msg->bufcount - 1] = 0; + if (newlen == 0 && msg->lm_bufcount > segment + 1) { + memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1], + (msg->lm_bufcount - segment - 1) * sizeof(__u32)); + msg->lm_buflens[msg->lm_bufcount - 1] = 0; } - req->rq_replen = lustre_msg_size(msg->bufcount, msg->buflens); + req->rq_replen = lustre_msg_size_v1(msg->lm_bufcount, msg->lm_buflens); +} + +void lustre_shrink_reply_v2(struct ptlrpc_request *req, int segment, + unsigned int newlen, int move_data) +{ + struct lustre_msg_v2 *msg = req->rq_repmsg; + char *tail = NULL, *newpos; + int tail_len = 0, n; + + LASSERT(req->rq_reply_state); + LASSERT(msg); + LASSERT(msg->lm_bufcount > segment); + LASSERT(msg->lm_buflens[segment] >= newlen); + + if (msg->lm_buflens[segment] == newlen) + return; + + if (move_data && msg->lm_bufcount > segment + 1) { + tail = lustre_msg_buf_v2(msg, segment + 1, 0); + for (n = segment + 1; n < msg->lm_bufcount; n++) + tail_len += size_round(msg->lm_buflens[n]); + } + + msg->lm_buflens[segment] = newlen; + + if (tail && tail_len) { + newpos = lustre_msg_buf_v2(msg, segment + 1, 0); + LASSERT(newpos <= tail); + if (newpos != tail) + memcpy(newpos, tail, tail_len); + } + + if (newlen == 0 && msg->lm_bufcount > segment + 1) { + memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1], + (msg->lm_bufcount - segment - 1) * sizeof(__u32)); + msg->lm_buflens[msg->lm_bufcount - 1] = 0; + } + + req->rq_replen = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens); +} + +/* + * shrink @segment to size @newlen. if @move_data is non-zero, we also move + * data forward from @segment + 1. + * + * if @newlen == 0, we remove the segment completely, but we still keep the + * totally bufcount the same to save possible data moving. this will leave a + * unused segment with size 0 at the tail, but that's ok. + * + * CAUTION: + * + if any buffers higher than @segment has been filled in, must call shrink + * with non-zero @move_data. + * + caller should NOT keep pointers to msg buffers which higher than @segment + * after call shrink. + */ +void lustre_shrink_reply(struct ptlrpc_request *req, int segment, + unsigned int newlen, int move_data) +{ + switch (req->rq_repmsg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + lustre_shrink_reply_v1(req, segment - 1, newlen, move_data); + return; + case LUSTRE_MSG_MAGIC_V2: + lustre_shrink_reply_v2(req, segment, newlen, move_data); + return; + default: + LASSERTF(0, "incorrect message magic: %08x\n", + req->rq_repmsg->lm_magic); + } } -void lustre_free_reply_state (struct ptlrpc_reply_state *rs) +void lustre_free_reply_state(struct ptlrpc_reply_state *rs) { PTLRPC_RS_DEBUG_LRU_DEL(rs); @@ -283,25 +644,106 @@ void lustre_free_reply_state (struct ptlrpc_reply_state *rs) } } -/* This returns the size of the buffer that is required to hold a lustre_msg - * with the given sub-buffer lengths. */ -int lustre_msg_size(int count, int *lengths) +int lustre_unpack_msg_v1(void *msg, int len) { - int size; - int i; + struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg; + int flipped, required_len, i; + ENTRY; - size = HDR_SIZE (count); - for (i = 0; i < count; i++) - size += size_round(lengths[i]); + /* Now we know the sender speaks my language. */ + required_len = lustre_msg_hdr_size_v1(0); + if (len < required_len) { + /* can't even look inside the message */ + CERROR("message length %d too small for lustre_msg\n", len); + RETURN(-EINVAL); + } + + flipped = lustre_msg_swabbed((struct lustre_msg *)m); + + if (flipped) { + __swab32s(&m->lm_type); + __swab32s(&m->lm_version); + __swab32s(&m->lm_opc); + __swab64s(&m->lm_last_xid); + __swab64s(&m->lm_last_committed); + __swab64s(&m->lm_transno); + __swab32s(&m->lm_status); + __swab32s(&m->lm_flags); + __swab32s(&m->lm_conn_cnt); + __swab32s(&m->lm_bufcount); + } + + if (m->lm_version != PTLRPC_MSG_VERSION) { + CERROR("wrong lustre_msg version %08x\n", m->lm_version); + RETURN(-EINVAL); + } + + required_len = lustre_msg_hdr_size_v1(m->lm_bufcount); + if (len < required_len) { + /* didn't receive all the buffer lengths */ + CERROR("message length %d too small for %d buflens\n", + len, m->lm_bufcount); + RETURN(-EINVAL); + } + + for (i = 0; i < m->lm_bufcount; i++) { + if (flipped) + __swab32s (&m->lm_buflens[i]); + required_len += size_round(m->lm_buflens[i]); + } + + if (len < required_len) { + CERROR("len: %d, required_len %d\n", len, required_len); + CERROR("bufcount: %d\n", m->lm_bufcount); + for (i = 0; i < m->lm_bufcount; i++) + CERROR("buffer %d length %d\n", i, m->lm_buflens[i]); + RETURN(-EINVAL); + } + + RETURN(0); +} + +static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len) +{ + int flipped, required_len, i; + ENTRY; + + required_len = lustre_msg_hdr_size_v2(m->lm_bufcount); + if (len < required_len) { + /* didn't receive all the buffer lengths */ + CERROR ("message length %d too small for %d buflens\n", + len, m->lm_bufcount); + RETURN(-EINVAL); + } + + flipped = lustre_msg_swabbed(m); + + if (flipped) { + __swab32s(&m->lm_bufcount); + __swab32s(&m->lm_secflvr); + __swab32s(&m->lm_repsize); + } + + for (i = 0; i < m->lm_bufcount; i++) { + if (flipped) + __swab32s(&m->lm_buflens[i]); + required_len += size_round(m->lm_buflens[i]); + } + + if (len < required_len) { + CERROR("len: %d, required_len %d\n", len, required_len); + CERROR("bufcount: %d\n", m->lm_bufcount); + for (i = 0; i < m->lm_bufcount; i++) + CERROR("buffer %d length %d\n", i, m->lm_buflens[i]); + RETURN(-EINVAL); + } - return size; + RETURN(0); } int lustre_unpack_msg(struct lustre_msg *m, int len) { - int flipped; - int required_len; - int i; + int required_len, rc; ENTRY; /* We can provide a slightly better error log, if we check the @@ -310,74 +752,84 @@ int lustre_unpack_msg(struct lustre_msg *m, int len) * rather than a short message. * */ - required_len = MAX (offsetof (struct lustre_msg, version) + - sizeof (m->version), - offsetof (struct lustre_msg, magic) + - sizeof (m->magic)); + required_len = offsetof(struct lustre_msg, lm_magic) + + sizeof(m->lm_magic); if (len < required_len) { /* can't even look inside the message */ - CERROR ("message length %d too small for magic/version check\n", - len); - RETURN (-EINVAL); + CERROR("message length %d too small for magic/version check\n", + len); + RETURN(-EINVAL); } - flipped = lustre_msg_swabbed(m); - if (flipped) - __swab32s (&m->version); - else if (m->magic != PTLRPC_MSG_MAGIC) { - CERROR("wrong lustre_msg magic %#08x\n", m->magic); - RETURN (-EINVAL); + switch (m->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + rc = lustre_unpack_msg_v1(m, len); + break; + 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; } - if ((m->version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) { - CERROR("wrong lustre_msg version %#08x\n", m->version); - RETURN (-EINVAL); - } + RETURN(rc); +} - /* Now we know the sender speaks my language (but possibly flipped)...*/ - required_len = HDR_SIZE(0); - if (len < required_len) { - /* can't even look inside the message */ - CERROR ("message length %d too small for lustre_msg\n", len); - RETURN (-EINVAL); - } +static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m) +{ + struct ptlrpc_body *pb; + ENTRY; - if (flipped) { - __swab32s (&m->type); - __swab32s (&m->opc); - __swab64s (&m->last_xid); - __swab64s (&m->last_committed); - __swab64s (&m->transno); - __swab32s (&m->status); - __swab32s (&m->flags); - __swab32s (&m->conn_cnt); - __swab32s (&m->bufcount); + pb = lustre_swab_buf(m, MSG_PTLRPC_BODY_OFF, sizeof(*pb), + lustre_swab_ptlrpc_body); + if (!pb) { + CERROR("error unpacking ptlrpc body"); + RETURN(-EFAULT); } - required_len = HDR_SIZE(m->bufcount); + if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) { + CERROR("wrong lustre_msg version %08x\n", pb->pb_version); + RETURN(-EINVAL); + } - if (len < required_len) { - /* didn't receive all the buffer lengths */ - CERROR ("message length %d too small for %d buflens\n", - len, m->bufcount); - RETURN(-EINVAL); - } + RETURN(0); +} - for (i = 0; i < m->bufcount; i++) { - if (flipped) - __swab32s (&m->buflens[i]); - required_len += size_round(m->buflens[i]); +int lustre_unpack_ptlrpc_body(struct lustre_msg *m) +{ + switch (m->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 lustre_unpack_ptlrpc_body_v2(m); + default: + CERROR("bad lustre msg magic: %#08X\n", m->lm_magic); + return -EINVAL; } +} - if (len < required_len) { - CERROR("len: %d, required_len %d\n", len, required_len); - CERROR("bufcount: %d\n", m->bufcount); - for (i = 0; i < m->bufcount; i++) - CERROR("buffer %d length %d\n", i, m->buflens[i]); - RETURN(-EINVAL); - } +static inline int lustre_msg_buflen_v1(void *msg, int n) +{ + struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg; - RETURN(0); + LASSERT(n >= 0); + if (n >= m->lm_bufcount) + return 0; + + return m->lm_buflens[n]; +} + +static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n) +{ + if (n >= m->lm_bufcount) + return 0; + + return m->lm_buflens[n]; } /** @@ -389,80 +841,125 @@ int lustre_unpack_msg(struct lustre_msg *m, int len) */ int lustre_msg_buflen(struct lustre_msg *m, int n) { - if (n >= m->bufcount) - return 0; - - return m->buflens[n]; + switch (m->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return lustre_msg_buflen_v1(m, n - 1); + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: + return lustre_msg_buflen_v2(m, n); + default: + LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic); + return -EINVAL; + } } EXPORT_SYMBOL(lustre_msg_buflen); -void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size) +static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len) { - int i; - int offset; - int buflen; - int bufcount; + struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg; - LASSERT (m != NULL); - LASSERT (n >= 0); + LASSERT(n >= 0); + if (n >= m->lm_bufcount) + LBUG(); - bufcount = m->bufcount; - if (n >= bufcount) { - CERROR("msg %p buffer[%d] not present (count %d)\n", - m, n, bufcount); - return NULL; - } + m->lm_buflens[n] = len; +} - buflen = m->buflens[n]; - if (buflen < min_size) { - CERROR("msg %p buffer[%d] size %d too small (required %d)\n", - m, n, buflen, min_size); - return NULL; +static inline int +lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len) +{ + if (n >= m->lm_bufcount) + LBUG(); + + m->lm_buflens[n] = len; +} + +void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len) +{ + switch (m->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + lustre_msg_set_buflen_v1(m, n - 1, len); + return; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: + lustre_msg_set_buflen_v2(m, n, len); + return; + default: + LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic); } +} - offset = HDR_SIZE(bufcount); - for (i = 0; i < n; i++) - offset += size_round(m->buflens[i]); +EXPORT_SYMBOL(lustre_msg_set_buflen); - return (char *)m + offset; +/* NB return the bufcount for lustre_msg_v2 format, so if message is packed + * in V1 format, the result is one bigger. (add struct ptlrpc_body). */ +int lustre_msg_bufcount(struct lustre_msg *m) +{ + switch (m->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: + return m->lm_bufcount; + default: + LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic); + return -EINVAL; + } } +EXPORT_SYMBOL(lustre_msg_bufcount); -char *lustre_msg_string (struct lustre_msg *m, int index, int max_len) +char *lustre_msg_string(struct lustre_msg *m, int index, int max_len) { /* max_len == 0 means the string should fill the buffer */ - char *str = lustre_msg_buf (m, index, 0); - int slen; - int blen; + char *str; + int slen, blen; + + switch (m->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + str = lustre_msg_buf_v1(m, index - 1, 0); + blen = lustre_msg_buflen_v1(m, index - 1); + break; + 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; + default: + LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic); + } if (str == NULL) { CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index); - return (NULL); + return NULL; } - blen = m->buflens[index]; - slen = strnlen (str, blen); + slen = strnlen(str, blen); if (slen == blen) { /* not NULL terminated */ - CERROR ("can't unpack non-NULL terminated string in " + CERROR("can't unpack non-NULL terminated string in " "msg %p buffer[%d] len %d\n", m, index, blen); - return (NULL); + return NULL; } if (max_len == 0) { if (slen != blen - 1) { - CERROR ("can't unpack short string in msg %p " - "buffer[%d] len %d: strlen %d\n", - m, index, blen, slen); - return (NULL); + CERROR("can't unpack short string in msg %p " + "buffer[%d] len %d: strlen %d\n", + m, index, blen, slen); + return NULL; } } else if (slen > max_len) { - CERROR ("can't unpack oversized string in msg %p " - "buffer[%d] len %d strlen %d: max %d expected\n", - m, index, blen, slen, max_len); - return (NULL); + CERROR("can't unpack oversized string in msg %p " + "buffer[%d] len %d strlen %d: max %d expected\n", + m, index, blen, slen, max_len); + return NULL; } - return (str); + return str; } /* Wrap up the normal fixed length cases */ @@ -471,7 +968,18 @@ void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size, { void *ptr; - ptr = lustre_msg_buf(msg, index, min_size); + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + ptr = lustre_msg_buf_v1(msg, index - 1, min_size); + break; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: + ptr = lustre_msg_buf_v2(msg, index, min_size); + break; + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } if (ptr == NULL) return NULL; @@ -495,9 +1003,538 @@ void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size, return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber); } +__u32 lustre_msg_get_flags(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_flags & + MSG_GEN_FLAG_MASK; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_flags; + } + default: + /* flags might be printed in debug code while message + * uninitialized */ + return 0; + } +} + +void lustre_msg_add_flags(struct lustre_msg *msg, int flags) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_flags |= + MSG_GEN_FLAG_MASK & flags; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_flags |= flags; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_flags(struct lustre_msg *msg, int flags) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK; + ((struct lustre_msg_v1 *)msg)->lm_flags |= + MSG_GEN_FLAG_MASK & flags; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_flags = flags; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_clear_flags(struct lustre_msg *msg, int flags) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + ((struct lustre_msg_v1 *)msg)->lm_flags &= + ~(MSG_GEN_FLAG_MASK & flags); + return; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_flags = 0; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +__u32 lustre_msg_get_op_flags(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_flags >> + MSG_OP_FLAG_SHIFT; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_op_flags; + } + default: + return 0; + } +} + +void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_flags |= + (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_op_flags |= flags; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK; + ((struct lustre_msg_v1 *)msg)->lm_flags |= + ((flags & MSG_GEN_FLAG_MASK) <pb_op_flags |= flags; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return &((struct lustre_msg_v1 *)msg)->lm_handle; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return &pb->pb_handle; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return NULL; + } +} + +__u32 lustre_msg_get_type(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_type; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_type; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + +__u32 lustre_msg_get_version(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_version; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_version; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + +void lustre_msg_add_version(struct lustre_msg *msg, int version) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_version |= version; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +__u32 lustre_msg_get_opc(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_opc; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_opc; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + +__u64 lustre_msg_get_last_xid(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_last_xid; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_last_xid; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + +__u64 lustre_msg_get_last_committed(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_last_committed; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_last_committed; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + +__u64 lustre_msg_get_transno(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_transno; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_transno; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + +__u32 lustre_msg_get_status(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_status; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_status; + } + default: + /* status might be printed in debug code while message + * uninitialized */ + return 0; + } +} + +__u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt; + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + return pb->pb_conn_cnt; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + +__u32 lustre_msg_get_magic(struct lustre_msg *msg) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + case LUSTRE_MSG_MAGIC_V1_SWABBED: + case LUSTRE_MSG_MAGIC_V2: + case LUSTRE_MSG_MAGIC_V2_SWABBED: + return msg->lm_magic; + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + return 0; + } +} + +void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_handle = *handle; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_handle = *handle; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_type(struct lustre_msg *msg, __u32 type) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_type = type; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_type = type; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_opc = opc; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_opc = opc; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_last_xid = last_xid; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_last_committed = last_committed; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_transno = transno; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_transno = transno; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_status(struct lustre_msg *msg, __u32 status) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_status = status; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_status = status; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + +void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt) +{ + switch (msg->lm_magic) { + case LUSTRE_MSG_MAGIC_V1: + ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt; + return; + case LUSTRE_MSG_MAGIC_V2: { + struct ptlrpc_body *pb; + + pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb)); + LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg); + pb->pb_conn_cnt = conn_cnt; + return; + } + default: + LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); + } +} + /* byte flipping routines for all wire types declared in * lustre_idl.h implemented here. */ +void lustre_swab_ptlrpc_body(struct ptlrpc_body *b) +{ + __swab32s (&b->pb_type); + __swab32s (&b->pb_version); + __swab32s (&b->pb_opc); + __swab32s (&b->pb_status); + __swab64s (&b->pb_last_xid); + __swab64s (&b->pb_last_committed); + __swab64s (&b->pb_transno); + __swab32s (&b->pb_flags); + __swab32s (&b->pb_op_flags); + __swab32s (&b->pb_conn_cnt); + __swab32s (&b->pb_paddings[0]); + __swab32s (&b->pb_paddings[1]); + __swab32s (&b->pb_paddings[2]); +} void lustre_swab_connect(struct obd_connect_data *ocd) { @@ -949,13 +1986,15 @@ void lustre_swab_qdata(struct qunit_data *d) void lustre_assert_wire_constants(void) { /* Wire protocol assertions generated by 'wirecheck' - * running on Linux vmbuild 2.6.9-build #8 Sun Dec 18 16:30:50 MST 2005 i686 i686 i386 GNU/Li - * with gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3) */ + * running on Linux localhost.localdomain 2.6.12-1.1372_FC3 #1 Fri Jul 15 00:59:10 EDT 2005 i + * with gcc version 3.4.4 20050721 (Red Hat 3.4.4-2) */ /* Constants... */ - LASSERTF(PTLRPC_MSG_MAGIC == 0x0BD00BD0," found %lld\n", - (long long)PTLRPC_MSG_MAGIC); + LASSERTF(LUSTRE_MSG_MAGIC_V1 == 0x0BD00BD0," found %lld\n", + (long long)LUSTRE_MSG_MAGIC_V1); + LASSERTF(LUSTRE_MSG_MAGIC_V2 == 0x0BD00BD2," found %lld\n", + (long long)LUSTRE_MSG_MAGIC_V2); LASSERTF(PTLRPC_MSG_VERSION == 0x00000003," found %lld\n", (long long)PTLRPC_MSG_VERSION); LASSERTF(PTL_RPC_MSG_REQUEST == 4711, " found %lld\n", @@ -1164,57 +2203,134 @@ void lustre_assert_wire_constants(void) LASSERTF((int)sizeof(((struct lustre_handle *)0)->cookie) == 8, " found %lld\n", (long long)(int)sizeof(((struct lustre_handle *)0)->cookie)); - /* Checks for struct lustre_msg */ - LASSERTF((int)sizeof(struct lustre_msg) == 64, " found %lld\n", - (long long)(int)sizeof(struct lustre_msg)); - LASSERTF((int)offsetof(struct lustre_msg, handle) == 0, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, handle)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->handle) == 8, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->handle)); - LASSERTF((int)offsetof(struct lustre_msg, magic) == 8, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, magic)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->magic) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->magic)); - LASSERTF((int)offsetof(struct lustre_msg, type) == 12, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, type)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->type) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->type)); - LASSERTF((int)offsetof(struct lustre_msg, version) == 16, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, version)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->version) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->version)); - LASSERTF((int)offsetof(struct lustre_msg, opc) == 20, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, opc)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->opc) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->opc)); - LASSERTF((int)offsetof(struct lustre_msg, last_xid) == 24, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, last_xid)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->last_xid) == 8, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->last_xid)); - LASSERTF((int)offsetof(struct lustre_msg, last_committed) == 32, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, last_committed)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->last_committed) == 8, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->last_committed)); - LASSERTF((int)offsetof(struct lustre_msg, transno) == 40, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, transno)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->transno) == 8, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->transno)); - LASSERTF((int)offsetof(struct lustre_msg, status) == 48, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, status)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->status) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->status)); - LASSERTF((int)offsetof(struct lustre_msg, flags) == 52, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, flags)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->flags) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->flags)); - LASSERTF((int)offsetof(struct lustre_msg, bufcount) == 60, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, bufcount)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->bufcount) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->bufcount)); - LASSERTF((int)offsetof(struct lustre_msg, buflens[7]) == 92, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, buflens[7])); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->buflens[7]) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->buflens[7])); + /* Checks for struct lustre_msg_v1 */ + LASSERTF((int)sizeof(struct lustre_msg_v1) == 64, " found %lld\n", + (long long)(int)sizeof(struct lustre_msg_v1)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_handle) == 0, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_handle)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_handle) == 8, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_handle)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_magic) == 8, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_magic)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_magic) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_magic)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_type) == 12, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_type)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_type) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_type)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_version) == 16, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_version)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_version) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_version)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_opc) == 20, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_opc)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_opc) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_opc)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_last_xid) == 24, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_last_xid)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_last_xid) == 8, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_last_xid)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_last_committed) == 32, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_last_committed)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_last_committed) == 8, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_last_committed)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_transno) == 40, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_transno)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_transno) == 8, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_transno)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_status) == 48, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_status)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_status) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_status)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_flags) == 52, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_flags)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_flags) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_flags)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_conn_cnt) == 56, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_conn_cnt)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_conn_cnt) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_conn_cnt)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_bufcount) == 60, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_bufcount)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_bufcount) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_bufcount)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_buflens[7]) == 92, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_buflens[7])); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_buflens[7]) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_buflens[7])); + + /* Checks for struct lustre_msg_v2 */ + LASSERTF((int)sizeof(struct lustre_msg_v2) == 16, " found %lld\n", + (long long)(int)sizeof(struct lustre_msg_v2)); + LASSERTF((int)offsetof(struct lustre_msg_v2, lm_bufcount) == 0, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v2, lm_bufcount)); + LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_bufcount) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_bufcount)); + LASSERTF((int)offsetof(struct lustre_msg_v2, lm_secflvr) == 4, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v2, lm_secflvr)); + LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_secflvr) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_secflvr)); + LASSERTF((int)offsetof(struct lustre_msg_v2, lm_magic) == 8, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v2, lm_magic)); + LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_magic) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_magic)); + LASSERTF((int)offsetof(struct lustre_msg_v2, lm_buflens[7]) == 44, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v2, lm_buflens[7])); + LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_buflens[7]) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_buflens[7])); + LASSERT(offsetof(struct lustre_msg_v1, lm_magic) == offsetof(struct lustre_msg_v2, lm_magic)); + + /* Checks for struct ptlrpc_body */ + LASSERTF((int)sizeof(struct ptlrpc_body) == 72, " found %lld\n", + (long long)(int)sizeof(struct ptlrpc_body)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_handle) == 0, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_handle)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_handle) == 8, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_handle)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_type) == 8, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_type)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_type) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_type)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_version) == 12, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_version)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_version) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_version)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_opc) == 16, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_opc)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_opc) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_opc)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_status) == 20, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_status)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_status) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_status)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_last_xid) == 24, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_last_xid)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_last_xid) == 8, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_last_xid)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_last_committed) == 32, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_last_committed)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_last_committed) == 8, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_last_committed)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_transno) == 40, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_transno)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_transno) == 8, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_transno)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_flags) == 48, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_flags)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_flags) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_flags)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_op_flags) == 52, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_op_flags)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_op_flags) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_op_flags)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_conn_cnt) == 56, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_conn_cnt)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_conn_cnt) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_conn_cnt)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_paddings[3]) == 72, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_paddings[3])); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_paddings[3]) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_paddings[3])); /* Checks for struct obdo */ LASSERTF((int)sizeof(struct obdo) == 208, " found %lld\n", @@ -2731,4 +3847,3 @@ void lustre_assert_wire_constants(void) LASSERTF((int)sizeof(((struct qunit_data *)0)->qd_isblk) == 4, " found %lld\n", (long long)(int)sizeof(((struct qunit_data *)0)->qd_isblk)); } - diff --git a/lustre/ptlrpc/pinger.c b/lustre/ptlrpc/pinger.c index d9007e1..2f595d5 100644 --- a/lustre/ptlrpc/pinger.c +++ b/lustre/ptlrpc/pinger.c @@ -45,13 +45,13 @@ int ptlrpc_ping(struct obd_import *imp) int rc = 0; ENTRY; - req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING, 0, NULL, NULL); + req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING, 1, NULL, NULL); if (req) { DEBUG_REQ(D_INFO, req, "pinging %s->%s", imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd)); req->rq_no_resend = req->rq_no_delay = 1; - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); ptlrpcd_add_req(req); } else { CERROR("OOM trying to ping %s->%s\n", @@ -509,13 +509,13 @@ static int pinger_check_rpcs(void *arg) } req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, OBD_PING, - 0, NULL, NULL); + 1, NULL, NULL); if (!req) { CERROR("out of memory\n"); break; } req->rq_no_resend = 1; - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); req->rq_send_state = LUSTRE_IMP_FULL; req->rq_phase = RQ_PHASE_RPC; req->rq_import_generation = generation; diff --git a/lustre/ptlrpc/ptlrpc_module.c b/lustre/ptlrpc/ptlrpc_module.c index 60adc71..dfc8b10 100644 --- a/lustre/ptlrpc/ptlrpc_module.c +++ b/lustre/ptlrpc/ptlrpc_module.c @@ -183,6 +183,7 @@ EXPORT_SYMBOL(lustre_shrink_reply); EXPORT_SYMBOL(lustre_free_reply_state); EXPORT_SYMBOL(lustre_msg_size); EXPORT_SYMBOL(lustre_unpack_msg); +EXPORT_SYMBOL(lustre_unpack_ptlrpc_body); EXPORT_SYMBOL(lustre_msg_buf); EXPORT_SYMBOL(lustre_msg_string); EXPORT_SYMBOL(lustre_swab_buf); @@ -216,6 +217,32 @@ EXPORT_SYMBOL(lustre_swab_ldlm_lock_desc); EXPORT_SYMBOL(lustre_swab_ldlm_request); EXPORT_SYMBOL(lustre_swab_ldlm_reply); EXPORT_SYMBOL(lustre_swab_qdata); +EXPORT_SYMBOL(lustre_msg_get_flags); +EXPORT_SYMBOL(lustre_msg_add_flags); +EXPORT_SYMBOL(lustre_msg_set_flags); +EXPORT_SYMBOL(lustre_msg_clear_flags); +EXPORT_SYMBOL(lustre_msg_get_op_flags); +EXPORT_SYMBOL(lustre_msg_add_op_flags); +EXPORT_SYMBOL(lustre_msg_set_op_flags); +EXPORT_SYMBOL(lustre_msg_get_handle ); +EXPORT_SYMBOL(lustre_msg_get_type); +EXPORT_SYMBOL(lustre_msg_get_version); +EXPORT_SYMBOL(lustre_msg_add_version); +EXPORT_SYMBOL(lustre_msg_get_opc); +EXPORT_SYMBOL(lustre_msg_get_last_xid); +EXPORT_SYMBOL(lustre_msg_get_last_committed); +EXPORT_SYMBOL(lustre_msg_get_transno); +EXPORT_SYMBOL(lustre_msg_get_status); +EXPORT_SYMBOL(lustre_msg_get_conn_cnt); +EXPORT_SYMBOL(lustre_msg_get_magic); +EXPORT_SYMBOL(lustre_msg_set_handle); +EXPORT_SYMBOL(lustre_msg_set_type); +EXPORT_SYMBOL(lustre_msg_set_opc); +EXPORT_SYMBOL(lustre_msg_set_last_xid); +EXPORT_SYMBOL(lustre_msg_set_last_committed); +EXPORT_SYMBOL(lustre_msg_set_transno); +EXPORT_SYMBOL(lustre_msg_set_status); +EXPORT_SYMBOL(lustre_msg_set_conn_cnt); EXPORT_SYMBOL(lustre_swab_mgs_target_info); /* recover.c */ diff --git a/lustre/ptlrpc/recov_thread.c b/lustre/ptlrpc/recov_thread.c index 8ad20c6..30286fb 100644 --- a/lustre/ptlrpc/recov_thread.c +++ b/lustre/ptlrpc/recov_thread.c @@ -64,9 +64,10 @@ static struct llog_commit_master *lcm = &lustre_lcm; static int llcd_alloc(void) { struct llog_canceld_ctxt *llcd; - int llcd_size = 0; + int llcd_size; - llcd_size = 4096 - lustre_msg_size(1, &llcd_size); + /* payload of lustre_msg V2 is bigger */ + llcd_size = 4096 - lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL); OBD_ALLOC(llcd, llcd_size + offsetof(struct llog_canceld_ctxt, llcd_cookies)); if (llcd == NULL) @@ -320,7 +321,9 @@ static int log_commit_thread(void *arg) /* We are the only one manipulating our local list - no lock */ list_for_each_entry_safe(llcd,n, &lcd->lcd_llcd_list,llcd_list){ - char *bufs[1] = {(char *)llcd->llcd_cookies}; + int size[2] = { sizeof(struct ptlrpc_body), + llcd->llcd_cookiebytes }; + char *bufs[2] = { NULL, (char *)llcd->llcd_cookies }; list_del(&llcd->llcd_list); if (llcd->llcd_cookiebytes == 0) { @@ -349,9 +352,7 @@ static int log_commit_thread(void *arg) } request = ptlrpc_prep_req(import, LUSTRE_LOG_VERSION, - OBD_LOG_CANCEL, 1, - &llcd->llcd_cookiebytes, - bufs); + OBD_LOG_CANCEL, 2, size,bufs); if (request == NULL) { rc = -ENOMEM; CERROR("error preparing commit: rc %d\n", rc); @@ -368,7 +369,7 @@ static int log_commit_thread(void *arg) request->rq_request_portal = LDLM_CANCEL_REQUEST_PORTAL; request->rq_reply_portal = LDLM_CANCEL_REPLY_PORTAL; - request->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(request, 1, NULL); mutex_down(&llcd->llcd_ctxt->loc_sem); if (llcd->llcd_ctxt->loc_imp == NULL) { mutex_up(&llcd->llcd_ctxt->loc_sem); diff --git a/lustre/ptlrpc/recover.c b/lustre/ptlrpc/recover.c index cbbed63..d43128d 100644 --- a/lustre/ptlrpc/recover.c +++ b/lustre/ptlrpc/recover.c @@ -277,7 +277,8 @@ void ptlrpc_request_handle_notconn(struct ptlrpc_request *failed_req) imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), imp->imp_connection->c_remote_uuid.uuid); - if (ptlrpc_set_import_discon(imp, failed_req->rq_reqmsg->conn_cnt)) { + if (ptlrpc_set_import_discon(imp, + lustre_msg_get_conn_cnt(failed_req->rq_reqmsg))) { if (!imp->imp_replayable) { CDEBUG(D_HA, "import %s@%s for %s not replayable, " "auto-deactivating\n", diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c index 55fd5b3..699c322 100644 --- a/lustre/ptlrpc/service.c +++ b/lustre/ptlrpc/service.c @@ -142,8 +142,8 @@ ptlrpc_save_lock (struct ptlrpc_request *req, struct ptlrpc_reply_state *rs = req->rq_reply_state; int idx; - LASSERT (rs != NULL); - LASSERT (rs->rs_nlocks < RS_MAX_LOCKS); + LASSERT(rs != NULL); + LASSERT(rs->rs_nlocks < RS_MAX_LOCKS); idx = rs->rs_nlocks++; rs->rs_locks[idx] = *lock; @@ -550,7 +550,7 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, /* Clear request swab mask; this is a new request */ request->rq_req_swab_mask = 0; #endif - rc = lustre_unpack_msg (request->rq_reqmsg, request->rq_reqlen); + rc = lustre_unpack_msg(request->rq_reqmsg, request->rq_reqlen); if (rc != 0) { CERROR ("error unpacking request: ptl %d from %s" " xid "LPU64"\n", svc->srv_req_portal, @@ -558,10 +558,18 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, goto out; } + rc = lustre_unpack_ptlrpc_body(request->rq_reqmsg); + if (rc) { + CERROR ("error unpacking ptlrpc body: ptl %d from %s" + " xid "LPU64"\n", svc->srv_req_portal, + libcfs_id2str(request->rq_peer), request->rq_xid); + goto out; + } + rc = -EINVAL; - if (request->rq_reqmsg->type != PTL_RPC_MSG_REQUEST) { + if (lustre_msg_get_type(request->rq_reqmsg) != PTL_RPC_MSG_REQUEST) { CERROR("wrong packet type received (type=%u) from %s\n", - request->rq_reqmsg->type, + lustre_msg_get_type(request->rq_reqmsg), libcfs_id2str(request->rq_peer)); goto out; } @@ -569,14 +577,15 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, CDEBUG(D_NET, "got req "LPD64"\n", request->rq_xid); request->rq_svc_thread = thread; - request->rq_export = class_conn2export(&request->rq_reqmsg->handle); + request->rq_export = class_conn2export( + lustre_msg_get_handle(request->rq_reqmsg)); if (request->rq_export) { - if (request->rq_reqmsg->conn_cnt < + if (lustre_msg_get_conn_cnt(request->rq_reqmsg) < request->rq_export->exp_conn_cnt) { DEBUG_REQ(D_ERROR, request, "DROPPING req from old connection %d < %d", - request->rq_reqmsg->conn_cnt, + lustre_msg_get_conn_cnt(request->rq_reqmsg), request->rq_export->exp_conn_cnt); goto put_conn; } @@ -599,7 +608,8 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, * REQ anyway (bug 1502) */ if (timediff / 1000000 > (long)obd_timeout) { CERROR("Dropping timed-out opc %d request from %s" - ": %ld seconds old\n", request->rq_reqmsg->opc, + ": %ld seconds old\n", + lustre_msg_get_opc(request->rq_reqmsg), libcfs_id2str(request->rq_peer), timediff / 1000000); goto put_conn; @@ -613,9 +623,9 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, (char *)request->rq_export->exp_client_uuid.uuid : "0"), (request->rq_export ? atomic_read(&request->rq_export->exp_refcount) : -99), - request->rq_reqmsg->status, request->rq_xid, + lustre_msg_get_status(request->rq_reqmsg), request->rq_xid, libcfs_id2str(request->rq_peer), - request->rq_reqmsg->opc); + lustre_msg_get_opc(request->rq_reqmsg)); rc = svc->srv_handler(request); @@ -627,9 +637,9 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc, (char *)request->rq_export->exp_client_uuid.uuid : "0"), (request->rq_export ? atomic_read(&request->rq_export->exp_refcount) : -99), - request->rq_reqmsg->status, request->rq_xid, + lustre_msg_get_status(request->rq_reqmsg), request->rq_xid, libcfs_id2str(request->rq_peer), - request->rq_reqmsg->opc); + lustre_msg_get_opc(request->rq_reqmsg)); put_conn: if (request->rq_export != NULL) @@ -643,25 +653,30 @@ put_conn: if (timediff / 1000000 > (long)obd_timeout) CERROR("request "LPU64" opc %u from %s processed in %lds " "trans "LPU64" rc %d/%d\n", - request->rq_xid, request->rq_reqmsg->opc, + request->rq_xid, lustre_msg_get_opc(request->rq_reqmsg), libcfs_id2str(request->rq_peer), cfs_timeval_sub(&work_end, &request->rq_arrival_time, NULL) / 1000000, - request->rq_repmsg ? request->rq_repmsg->transno : - request->rq_transno, request->rq_status, - request->rq_repmsg ? request->rq_repmsg->status : -999); + request->rq_repmsg ? + lustre_msg_get_transno(request->rq_repmsg) : + request->rq_transno, request->rq_status, + request->rq_repmsg ? + lustre_msg_get_status(request->rq_repmsg) : + -999); else CDEBUG(D_HA, "request "LPU64" opc %u from %s processed in " "%ldus (%ldus total) trans "LPU64" rc %d/%d\n", - request->rq_xid, request->rq_reqmsg->opc, + request->rq_xid, lustre_msg_get_opc(request->rq_reqmsg), libcfs_id2str(request->rq_peer), timediff, cfs_timeval_sub(&work_end, &request->rq_arrival_time, NULL), request->rq_transno, request->rq_status, - request->rq_repmsg ? request->rq_repmsg->status : -999); + request->rq_repmsg ? + lustre_msg_get_status(request->rq_repmsg) : + -999); if (svc->srv_stats != NULL) { - int opc = opcode_offset(request->rq_reqmsg->opc); + int opc = opcode_offset(lustre_msg_get_opc(request->rq_reqmsg)); if (opc > 0) { LASSERT(opc < LUSTRE_MAX_OPCODES); lprocfs_counter_add(svc->srv_stats, @@ -731,12 +746,11 @@ ptlrpc_server_handle_reply (struct ptlrpc_service *svc) " o%d NID %s\n", rs, rs->rs_xid, rs->rs_transno, - rs->rs_msg.opc, + lustre_msg_get_opc(rs->rs_msg), libcfs_nid2str(exp->exp_connection->c_peer.nid)); } - if ((!been_handled && rs->rs_on_net) || - nlocks > 0) { + if ((!been_handled && rs->rs_on_net) || nlocks > 0) { spin_unlock_irqrestore(&svc->srv_lock, flags); if (!been_handled && rs->rs_on_net) { diff --git a/lustre/quota/quota_check.c b/lustre/quota/quota_check.c index d733ede..9defa13 100644 --- a/lustre/quota/quota_check.c +++ b/lustre/quota/quota_check.c @@ -49,18 +49,18 @@ static int target_quotacheck_callback(struct obd_export *exp, { struct ptlrpc_request *req; struct obd_quotactl *body; - int rc, size = sizeof(*oqctl); + int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*oqctl) }; ENTRY; req = ptlrpc_prep_req(exp->exp_imp_reverse, LUSTRE_OBD_VERSION, - OBD_QC_CALLBACK, 1, &size, NULL); + OBD_QC_CALLBACK, 2, size, NULL); if (!req) RETURN(-ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); *body = *oqctl; - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); rc = ptlrpc_queue_wait(req); ptlrpc_req_finished(req); @@ -153,29 +153,28 @@ int client_quota_check(struct obd_export *exp, struct obd_quotactl *oqctl) struct client_obd *cli = &exp->exp_obd->u.cli; struct ptlrpc_request *req; struct obd_quotactl *body; - int size = sizeof(*body), opc, version; - int rc; + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) }; + int ver, opc, rc; ENTRY; if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) { - version = LUSTRE_MDS_VERSION; + ver = LUSTRE_MDS_VERSION; opc = MDS_QUOTACHECK; } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) { - version = LUSTRE_OST_VERSION; + ver = LUSTRE_OST_VERSION; opc = OST_QUOTACHECK; } else { RETURN(-EINVAL); } - req = ptlrpc_prep_req(class_exp2cliimp(exp), version, opc, 1, &size, - NULL); + req = ptlrpc_prep_req(class_exp2cliimp(exp), ver, opc, 2, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); - body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body)); + body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body)); *body = *oqctl; - req->rq_replen = lustre_msg_size(0, NULL); + ptlrpc_req_set_repsize(req, 1, NULL); /* the next poll will find -ENODATA, that means quotacheck is * going on */ diff --git a/lustre/quota/quota_context.c b/lustre/quota/quota_context.c index 013eead1..c807e26 100644 --- a/lustre/quota/quota_context.c +++ b/lustre/quota/quota_context.c @@ -432,7 +432,8 @@ static int dqacq_interpret(struct ptlrpc_request *req, void *data, int rc) struct qunit_data *qdata = NULL; ENTRY; - qdata = lustre_swab_repbuf(req, 0, sizeof(*qdata), lustre_swab_qdata); + qdata = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*qdata), + lustre_swab_qdata); if (rc == 0 && qdata == NULL) RETURN(-EPROTO); @@ -442,9 +443,11 @@ static int dqacq_interpret(struct ptlrpc_request *req, void *data, int rc) qdata->qd_count == 0)); QDATA_DEBUG(qdata, "%s interpret rc(%d).\n", - req->rq_reqmsg->opc == QUOTA_DQACQ ? "DQACQ" : "DQREL", rc); + lustre_msg_get_opc(req->rq_reqmsg) == QUOTA_DQACQ ? + "DQACQ" : "DQREL", rc); - rc = dqacq_completion(obd, qctxt, qdata, rc, req->rq_reqmsg->opc); + rc = dqacq_completion(obd, qctxt, qdata, rc, + lustre_msg_get_opc(req->rq_reqmsg)); RETURN(rc); } @@ -470,7 +473,7 @@ schedule_dqacq(struct obd_device *obd, struct ptlrpc_request *req; struct qunit_data *reqdata; struct dqacq_async_args *aa; - int size = sizeof(*reqdata); + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*reqdata) }; int rc = 0; ENTRY; @@ -512,17 +515,17 @@ schedule_dqacq(struct obd_device *obd, /* build dqacq/dqrel request */ LASSERT(qctxt->lqc_import); - req = ptlrpc_prep_req(qctxt->lqc_import, LUSTRE_MDS_VERSION, opc, 1, - &size, NULL); + req = ptlrpc_prep_req(qctxt->lqc_import, LUSTRE_MDS_VERSION, opc, 2, + size, NULL); if (!req) { dqacq_completion(obd, qctxt, qdata, -ENOMEM, opc); RETURN(-ENOMEM); } - reqdata = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*reqdata)); + reqdata = lustre_msg_buf(req->rq_reqmsg, REPLY_REC_OFF, + sizeof(*reqdata)); *reqdata = *qdata; - size = sizeof(*reqdata); - req->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); aa = (struct dqacq_async_args *)&req->rq_async_args; diff --git a/lustre/quota/quota_ctl.c b/lustre/quota/quota_ctl.c index d3354b4..64490bd 100644 --- a/lustre/quota/quota_ctl.c +++ b/lustre/quota/quota_ctl.c @@ -181,33 +181,32 @@ int client_quota_ctl(struct obd_export *exp, struct obd_quotactl *oqctl) { struct ptlrpc_request *req; struct obd_quotactl *oqc; - int size = sizeof(*oqctl), opc, version; - int rc; + int size[2] = { sizeof(struct ptlrpc_body), sizeof(*oqctl) }; + int ver, opc, rc; ENTRY; if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDC_NAME)) { + ver = LUSTRE_MDS_VERSION, opc = MDS_QUOTACTL; - version = LUSTRE_MDS_VERSION; } else if (!strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_OSC_NAME)) { + ver = LUSTRE_OST_VERSION, opc = OST_QUOTACTL; - version = LUSTRE_OST_VERSION; } else { RETURN(-EINVAL); } - req = ptlrpc_prep_req(class_exp2cliimp(exp), version, opc, 1, &size, - NULL); + req = ptlrpc_prep_req(class_exp2cliimp(exp), ver, opc, 2, size, NULL); if (!req) GOTO(out, rc = -ENOMEM); - oqc = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*oqctl)); + oqc = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*oqctl)); *oqc = *oqctl; - req->rq_replen = lustre_msg_size(1, &size); + ptlrpc_req_set_repsize(req, 2, size); rc = ptlrpc_queue_wait(req); if (!rc) { - oqc = lustre_swab_repbuf(req, 0, sizeof (*oqc), + oqc = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*oqc), lustre_swab_obd_quotactl); if (oqc == NULL) { CERROR ("Can't unpack obd_quotactl\n"); diff --git a/lustre/tests/cfg/local.sh b/lustre/tests/cfg/local.sh index ca7258e..2526a9f 100644 --- a/lustre/tests/cfg/local.sh +++ b/lustre/tests/cfg/local.sh @@ -26,7 +26,8 @@ STRIPE_BYTES=${STRIPE_BYTES:-1048576} STRIPES_PER_OBJ=${STRIPES_PER_OBJ:-0} TIMEOUT=${TIMEOUT:-20} UPCALL=${UPCALL:-DEFAULT} -PTLDEBUG=${PTLDEBUG:-0x33f0404} +#PTLDEBUG=${PTLDEBUG:-0x33f0404} +PTLDEBUG=${PTLDEBUG:-0xffffffff} SUBSYSTEM=${SUBSYSTEM:- 0xffb7e3ff} MKFSOPT="" diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 77a75ec8f..bd208f3 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -2690,7 +2690,7 @@ test_75() { $CHECKSTAT -a ${FHEAD}_tmp || error "${FHEAD}_tmp exist after join" $CHECKSTAT -a ${FTAIL} || error "tail ${FTAIL} exist after join (2)" - rm -rf ${FHEAD} || "delete join file error" + rm -rf ${FHEAD} || error "delete join file error" cp -p ${F128k} ${F}_join_10_compare cp -p ${F128k} ${F}_join_10 for ((i = 0; i < 10; i++)); do diff --git a/lustre/utils/wirecheck.c b/lustre/utils/wirecheck.c index 3eaf67c..9aa1d66 100644 --- a/lustre/utils/wirecheck.c +++ b/lustre/utils/wirecheck.c @@ -62,7 +62,7 @@ do { \ #define CHECK_MEMBER(s,m) \ do { \ CHECK_MEMBER_OFFSET(s, m); \ - CHECK_MEMBER_SIZEOF(s, m); \ + CHECK_MEMBER_SIZEOF(s, m); \ } while(0) #define CHECK_STRUCT(s) \ @@ -80,23 +80,54 @@ check_lustre_handle(void) CHECK_MEMBER(lustre_handle, cookie); } -static void -check_lustre_msg(void) +void +check_lustre_msg_v1(void) +{ + BLANK_LINE(); + CHECK_STRUCT(lustre_msg_v1); + CHECK_MEMBER(lustre_msg_v1, lm_handle); + CHECK_MEMBER(lustre_msg_v1, lm_magic); + CHECK_MEMBER(lustre_msg_v1, lm_type); + CHECK_MEMBER(lustre_msg_v1, lm_version); + CHECK_MEMBER(lustre_msg_v1, lm_opc); + CHECK_MEMBER(lustre_msg_v1, lm_last_xid); + CHECK_MEMBER(lustre_msg_v1, lm_last_committed); + CHECK_MEMBER(lustre_msg_v1, lm_transno); + CHECK_MEMBER(lustre_msg_v1, lm_status); + CHECK_MEMBER(lustre_msg_v1, lm_flags); + CHECK_MEMBER(lustre_msg_v1, lm_conn_cnt); + CHECK_MEMBER(lustre_msg_v1, lm_bufcount); + CHECK_MEMBER(lustre_msg_v1, lm_buflens[7]); +} + +void +check_lustre_msg_v2(void) +{ + BLANK_LINE(); + CHECK_STRUCT(lustre_msg_v2); + CHECK_MEMBER(lustre_msg_v2, lm_bufcount); + CHECK_MEMBER(lustre_msg_v2, lm_secflvr); + CHECK_MEMBER(lustre_msg_v2, lm_magic); + CHECK_MEMBER(lustre_msg_v2, lm_buflens[7]); +} + +void +check_ptlrpc_body(void) { BLANK_LINE(); - CHECK_STRUCT(lustre_msg); - CHECK_MEMBER(lustre_msg, handle); - CHECK_MEMBER(lustre_msg, magic); - CHECK_MEMBER(lustre_msg, type); - CHECK_MEMBER(lustre_msg, version); - CHECK_MEMBER(lustre_msg, opc); - CHECK_MEMBER(lustre_msg, last_xid); - CHECK_MEMBER(lustre_msg, last_committed); - CHECK_MEMBER(lustre_msg, transno); - CHECK_MEMBER(lustre_msg, status); - CHECK_MEMBER(lustre_msg, flags); - CHECK_MEMBER(lustre_msg, bufcount); - CHECK_MEMBER(lustre_msg, buflens[7]); + CHECK_STRUCT(ptlrpc_body); + CHECK_MEMBER(ptlrpc_body, pb_handle); + CHECK_MEMBER(ptlrpc_body, pb_type); + CHECK_MEMBER(ptlrpc_body, pb_version); + CHECK_MEMBER(ptlrpc_body, pb_opc); + CHECK_MEMBER(ptlrpc_body, pb_status); + CHECK_MEMBER(ptlrpc_body, pb_last_xid); + CHECK_MEMBER(ptlrpc_body, pb_last_committed); + CHECK_MEMBER(ptlrpc_body, pb_transno); + CHECK_MEMBER(ptlrpc_body, pb_flags); + CHECK_MEMBER(ptlrpc_body, pb_op_flags); + CHECK_MEMBER(ptlrpc_body, pb_conn_cnt); + CHECK_MEMBER(ptlrpc_body, pb_paddings[3]); } static void @@ -954,7 +985,8 @@ main(int argc, char **argv) BLANK_LINE (); COMMENT("Constants..."); - CHECK_DEFINE(PTLRPC_MSG_MAGIC); + CHECK_DEFINE(LUSTRE_MSG_MAGIC_V1); + CHECK_DEFINE(LUSTRE_MSG_MAGIC_V2); CHECK_DEFINE(PTLRPC_MSG_VERSION); CHECK_VALUE(PTL_RPC_MSG_REQUEST); @@ -1089,7 +1121,11 @@ main(int argc, char **argv) COMMENT("Sizes and Offsets"); BLANK_LINE(); check_lustre_handle(); - check_lustre_msg(); + check_lustre_msg_v1(); + check_lustre_msg_v2(); + printf(" LASSERT(offsetof(struct lustre_msg_v1, lm_magic) == " + "offsetof(struct lustre_msg_v2, lm_magic));\n"); + check_ptlrpc_body(); check_obdo(); check_lov_mds_md_v1(); check_lov_mds_md_join(); diff --git a/lustre/utils/wiretest.c b/lustre/utils/wiretest.c index d57d4d7..0ce8377 100644 --- a/lustre/utils/wiretest.c +++ b/lustre/utils/wiretest.c @@ -27,13 +27,15 @@ int main() void lustre_assert_wire_constants(void) { /* Wire protocol assertions generated by 'wirecheck' - * running on Linux pancake.rutmans.org 2.6.8-1.521 #1 Mon Aug 16 09:01:18 EDT 2004 i686 i686 - * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) */ + * running on Linux localhost.localdomain 2.6.12-1.1372_FC3 #1 Fri Jul 15 00:59:10 EDT 2005 i + * with gcc version 3.4.4 20050721 (Red Hat 3.4.4-2) */ /* Constants... */ - LASSERTF(PTLRPC_MSG_MAGIC == 0x0BD00BD0," found %lld\n", - (long long)PTLRPC_MSG_MAGIC); + LASSERTF(LUSTRE_MSG_MAGIC_V1 == 0x0BD00BD0," found %lld\n", + (long long)LUSTRE_MSG_MAGIC_V1); + LASSERTF(LUSTRE_MSG_MAGIC_V2 == 0x0BD00BD2," found %lld\n", + (long long)LUSTRE_MSG_MAGIC_V2); LASSERTF(PTLRPC_MSG_VERSION == 0x00000003," found %lld\n", (long long)PTLRPC_MSG_VERSION); LASSERTF(PTL_RPC_MSG_REQUEST == 4711, " found %lld\n", @@ -252,57 +254,134 @@ void lustre_assert_wire_constants(void) LASSERTF((int)sizeof(((struct lustre_handle *)0)->cookie) == 8, " found %lld\n", (long long)(int)sizeof(((struct lustre_handle *)0)->cookie)); - /* Checks for struct lustre_msg */ - LASSERTF((int)sizeof(struct lustre_msg) == 64, " found %lld\n", - (long long)(int)sizeof(struct lustre_msg)); - LASSERTF((int)offsetof(struct lustre_msg, handle) == 0, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, handle)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->handle) == 8, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->handle)); - LASSERTF((int)offsetof(struct lustre_msg, magic) == 8, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, magic)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->magic) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->magic)); - LASSERTF((int)offsetof(struct lustre_msg, type) == 12, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, type)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->type) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->type)); - LASSERTF((int)offsetof(struct lustre_msg, version) == 16, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, version)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->version) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->version)); - LASSERTF((int)offsetof(struct lustre_msg, opc) == 20, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, opc)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->opc) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->opc)); - LASSERTF((int)offsetof(struct lustre_msg, last_xid) == 24, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, last_xid)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->last_xid) == 8, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->last_xid)); - LASSERTF((int)offsetof(struct lustre_msg, last_committed) == 32, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, last_committed)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->last_committed) == 8, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->last_committed)); - LASSERTF((int)offsetof(struct lustre_msg, transno) == 40, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, transno)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->transno) == 8, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->transno)); - LASSERTF((int)offsetof(struct lustre_msg, status) == 48, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, status)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->status) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->status)); - LASSERTF((int)offsetof(struct lustre_msg, flags) == 52, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, flags)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->flags) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->flags)); - LASSERTF((int)offsetof(struct lustre_msg, bufcount) == 60, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, bufcount)); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->bufcount) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->bufcount)); - LASSERTF((int)offsetof(struct lustre_msg, buflens[7]) == 92, " found %lld\n", - (long long)(int)offsetof(struct lustre_msg, buflens[7])); - LASSERTF((int)sizeof(((struct lustre_msg *)0)->buflens[7]) == 4, " found %lld\n", - (long long)(int)sizeof(((struct lustre_msg *)0)->buflens[7])); + /* Checks for struct lustre_msg_v1 */ + LASSERTF((int)sizeof(struct lustre_msg_v1) == 64, " found %lld\n", + (long long)(int)sizeof(struct lustre_msg_v1)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_handle) == 0, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_handle)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_handle) == 8, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_handle)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_magic) == 8, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_magic)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_magic) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_magic)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_type) == 12, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_type)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_type) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_type)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_version) == 16, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_version)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_version) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_version)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_opc) == 20, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_opc)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_opc) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_opc)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_last_xid) == 24, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_last_xid)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_last_xid) == 8, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_last_xid)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_last_committed) == 32, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_last_committed)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_last_committed) == 8, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_last_committed)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_transno) == 40, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_transno)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_transno) == 8, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_transno)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_status) == 48, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_status)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_status) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_status)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_flags) == 52, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_flags)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_flags) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_flags)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_conn_cnt) == 56, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_conn_cnt)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_conn_cnt) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_conn_cnt)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_bufcount) == 60, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_bufcount)); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_bufcount) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_bufcount)); + LASSERTF((int)offsetof(struct lustre_msg_v1, lm_buflens[7]) == 92, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v1, lm_buflens[7])); + LASSERTF((int)sizeof(((struct lustre_msg_v1 *)0)->lm_buflens[7]) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v1 *)0)->lm_buflens[7])); + + /* Checks for struct lustre_msg_v2 */ + LASSERTF((int)sizeof(struct lustre_msg_v2) == 16, " found %lld\n", + (long long)(int)sizeof(struct lustre_msg_v2)); + LASSERTF((int)offsetof(struct lustre_msg_v2, lm_bufcount) == 0, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v2, lm_bufcount)); + LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_bufcount) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_bufcount)); + LASSERTF((int)offsetof(struct lustre_msg_v2, lm_secflvr) == 4, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v2, lm_secflvr)); + LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_secflvr) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_secflvr)); + LASSERTF((int)offsetof(struct lustre_msg_v2, lm_magic) == 8, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v2, lm_magic)); + LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_magic) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_magic)); + LASSERTF((int)offsetof(struct lustre_msg_v2, lm_buflens[7]) == 44, " found %lld\n", + (long long)(int)offsetof(struct lustre_msg_v2, lm_buflens[7])); + LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_buflens[7]) == 4, " found %lld\n", + (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_buflens[7])); + LASSERT(offsetof(struct lustre_msg_v1, lm_magic) == offsetof(struct lustre_msg_v2, lm_magic)); + + /* Checks for struct ptlrpc_body */ + LASSERTF((int)sizeof(struct ptlrpc_body) == 72, " found %lld\n", + (long long)(int)sizeof(struct ptlrpc_body)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_handle) == 0, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_handle)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_handle) == 8, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_handle)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_type) == 8, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_type)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_type) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_type)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_version) == 12, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_version)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_version) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_version)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_opc) == 16, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_opc)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_opc) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_opc)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_status) == 20, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_status)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_status) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_status)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_last_xid) == 24, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_last_xid)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_last_xid) == 8, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_last_xid)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_last_committed) == 32, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_last_committed)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_last_committed) == 8, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_last_committed)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_transno) == 40, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_transno)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_transno) == 8, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_transno)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_flags) == 48, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_flags)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_flags) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_flags)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_op_flags) == 52, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_op_flags)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_op_flags) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_op_flags)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_conn_cnt) == 56, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_conn_cnt)); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_conn_cnt) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_conn_cnt)); + LASSERTF((int)offsetof(struct ptlrpc_body, pb_paddings[3]) == 72, " found %lld\n", + (long long)(int)offsetof(struct ptlrpc_body, pb_paddings[3])); + LASSERTF((int)sizeof(((struct ptlrpc_body *)0)->pb_paddings[3]) == 4, " found %lld\n", + (long long)(int)sizeof(((struct ptlrpc_body *)0)->pb_paddings[3])); /* Checks for struct obdo */ LASSERTF((int)sizeof(struct obdo) == 208, " found %lld\n", -- 1.8.3.1