From fb3ed0fe68e324f8d6e002a32486de7f5d38f2e3 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Wed, 4 Dec 2019 18:28:11 +1100 Subject: [PATCH] LU-13004 lnet: always pass struct lnet_md by reference. Both LNetMDAttach and LNetMDBind expected a struct lnet_md to be passed by value. This requires copying the data structure onto the stack, which is a waste of stack space and brings no value. So change them to expect a reference, and declare it 'const' to be sure it doesn't get changed. Signed-off-by: Mr NeilBrown Change-Id: I343797d1e70cc85fde92d544e56536e982e02973 Reviewed-on: https://review.whamcloud.com/37853 Reviewed-by: Serguei Smirnov Tested-by: jenkins Reviewed-by: Chris Horn Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lnet/include/lnet/api.h | 4 ++-- lnet/lnet/api-ni.c | 6 +++--- lnet/lnet/lib-md.c | 24 ++++++++++++------------ lnet/lnet/lib-move.c | 2 +- lnet/lnet/peer.c | 2 +- lnet/selftest/rpc.c | 4 ++-- lustre/ptlrpc/niobuf.c | 10 +++++----- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lnet/include/lnet/api.h b/lnet/include/lnet/api.h index bc6e9d9..f552349 100644 --- a/lnet/include/lnet/api.h +++ b/lnet/include/lnet/api.h @@ -119,11 +119,11 @@ void LNetMEUnlink(struct lnet_me *current_in); * associated with a MD: LNetMDUnlink(). * @{ */ int LNetMDAttach(struct lnet_me *current_in, - struct lnet_md md_in, + const struct lnet_md *md_in, enum lnet_unlink unlink_in, struct lnet_handle_md *md_handle_out); -int LNetMDBind(struct lnet_md md_in, +int LNetMDBind(const struct lnet_md *md_in, enum lnet_unlink unlink_in, struct lnet_handle_md *md_handle_out); diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 05c0cb3..0d5e45b 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -1724,7 +1724,7 @@ lnet_ping_target_setup(struct lnet_ping_buffer **ppbuf, md.handler = the_lnet.ln_ping_target_handler; md.user_ptr = *ppbuf; - rc = LNetMDAttach(me, md, LNET_RETAIN, ping_mdh); + rc = LNetMDAttach(me, &md, LNET_RETAIN, ping_mdh); if (rc != 0) { CERROR("Can't attach ping target MD: %d\n", rc); goto fail_unlink_ping_me; @@ -1933,7 +1933,7 @@ int lnet_push_target_post(struct lnet_ping_buffer *pbuf, md.user_ptr = pbuf; md.handler = the_lnet.ln_push_target_handler; - rc = LNetMDAttach(me, md, LNET_UNLINK, mdhp); + rc = LNetMDAttach(me, &md, LNET_UNLINK, mdhp); if (rc) { CERROR("Can't attach push MD: %d\n", rc); LNetMEUnlink(me); @@ -4160,7 +4160,7 @@ static int lnet_ping(struct lnet_process_id id, signed long timeout, init_completion(&pd.completion); - rc = LNetMDBind(md, LNET_UNLINK, &pd.mdh); + rc = LNetMDBind(&md, LNET_UNLINK, &pd.mdh); if (rc != 0) { CERROR("Can't bind MD: %d\n", rc); goto fail_ping_buffer_decref; diff --git a/lnet/lnet/lib-md.c b/lnet/lnet/lib-md.c index 0ab9060..268e856 100644 --- a/lnet/lnet/lib-md.c +++ b/lnet/lnet/lib-md.c @@ -142,7 +142,7 @@ out: } static struct lnet_libmd * -lnet_md_build(struct lnet_md *umd, int unlink) +lnet_md_build(const struct lnet_md *umd, int unlink) { int i; unsigned int niov; @@ -299,7 +299,7 @@ lnet_md_deconstruct(struct lnet_libmd *lmd, struct lnet_event *ev) } static int -lnet_md_validate(struct lnet_md *umd) +lnet_md_validate(const struct lnet_md *umd) { if (umd->start == NULL && umd->length != 0) { CERROR("MD start pointer can not be NULL with length %u\n", @@ -343,7 +343,7 @@ lnet_md_validate(struct lnet_md *umd) * a MD. */ int -LNetMDAttach(struct lnet_me *me, struct lnet_md umd, +LNetMDAttach(struct lnet_me *me, const struct lnet_md *umd, enum lnet_unlink unlink, struct lnet_handle_md *handle) { LIST_HEAD(matches); @@ -354,15 +354,15 @@ LNetMDAttach(struct lnet_me *me, struct lnet_md umd, LASSERT(the_lnet.ln_refcount > 0); - if (lnet_md_validate(&umd) != 0) + if (lnet_md_validate(umd) != 0) return -EINVAL; - if ((umd.options & (LNET_MD_OP_GET | LNET_MD_OP_PUT)) == 0) { + if ((umd->options & (LNET_MD_OP_GET | LNET_MD_OP_PUT)) == 0) { CERROR("Invalid option: no MD_OP set\n"); return -EINVAL; } - md = lnet_md_build(&umd, unlink); + md = lnet_md_build(umd, unlink); if (IS_ERR(md)) return PTR_ERR(md); @@ -373,7 +373,7 @@ LNetMDAttach(struct lnet_me *me, struct lnet_md umd, if (me->me_md) rc = -EBUSY; else - rc = lnet_md_link(md, umd.handler, cpt); + rc = lnet_md_link(md, umd->handler, cpt); if (rc != 0) goto out_unlock; @@ -415,7 +415,7 @@ EXPORT_SYMBOL(LNetMDAttach); * LNetInvalidateHandle() on it. */ int -LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink, +LNetMDBind(const struct lnet_md *umd, enum lnet_unlink unlink, struct lnet_handle_md *handle) { struct lnet_libmd *md; @@ -424,15 +424,15 @@ LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink, LASSERT(the_lnet.ln_refcount > 0); - if (lnet_md_validate(&umd) != 0) + if (lnet_md_validate(umd) != 0) return -EINVAL; - if ((umd.options & (LNET_MD_OP_GET | LNET_MD_OP_PUT)) != 0) { + if ((umd->options & (LNET_MD_OP_GET | LNET_MD_OP_PUT)) != 0) { CERROR("Invalid option: GET|PUT illegal on active MDs\n"); return -EINVAL; } - md = lnet_md_build(&umd, unlink); + md = lnet_md_build(umd, unlink); if (IS_ERR(md)) return PTR_ERR(md); @@ -445,7 +445,7 @@ LNetMDBind(struct lnet_md umd, enum lnet_unlink unlink, cpt = lnet_res_lock_current(); - rc = lnet_md_link(md, umd.handler, cpt); + rc = lnet_md_link(md, umd->handler, cpt); if (rc != 0) goto out_unlock; diff --git a/lnet/lnet/lib-move.c b/lnet/lnet/lib-move.c index 30f0d71..9cf30c2 100644 --- a/lnet/lnet/lib-move.c +++ b/lnet/lnet/lib-move.c @@ -3573,7 +3573,7 @@ lnet_send_ping(lnet_nid_t dest_nid, md.user_ptr = user_data; md.handler = handler; - rc = LNetMDBind(md, LNET_UNLINK, mdh); + rc = LNetMDBind(&md, LNET_UNLINK, mdh); if (rc) { lnet_ping_buffer_decref(pbuf); CERROR("Can't bind MD: %d\n", rc); diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index 3719a74..b745eb3 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -3094,7 +3094,7 @@ __must_hold(&lp->lp_lock) md.handler = the_lnet.ln_dc_handler; md.user_ptr = lp; - rc = LNetMDBind(md, LNET_UNLINK, &lp->lp_push_mdh); + rc = LNetMDBind(&md, LNET_UNLINK, &lp->lp_push_mdh); if (rc) { lnet_ping_buffer_decref(pbuf); CERROR("Can't bind push source MD: %d\n", rc); diff --git a/lnet/selftest/rpc.c b/lnet/selftest/rpc.c index 99e3774..db6c704 100644 --- a/lnet/selftest/rpc.c +++ b/lnet/selftest/rpc.c @@ -375,7 +375,7 @@ srpc_post_passive_rdma(int portal, int local, __u64 matchbits, void *buf, md.options = options; md.handler = srpc_data.rpc_lnet_handler; - rc = LNetMDAttach(me, md, LNET_UNLINK, mdh); + rc = LNetMDAttach(me, &md, LNET_UNLINK, mdh); if (rc != 0) { CERROR("LNetMDAttach failed: %d\n", rc); LASSERT(rc == -ENOMEM); @@ -406,7 +406,7 @@ srpc_post_active_rdma(int portal, __u64 matchbits, void *buf, int len, md.threshold = ((options & LNET_MD_OP_GET) != 0) ? 2 : 1; md.options = options & ~(LNET_MD_OP_PUT | LNET_MD_OP_GET); - rc = LNetMDBind(md, LNET_UNLINK, mdh); + rc = LNetMDBind(&md, LNET_UNLINK, mdh); if (rc != 0) { CERROR("LNetMDBind failed: %d\n", rc); LASSERT(rc == -ENOMEM); diff --git a/lustre/ptlrpc/niobuf.c b/lustre/ptlrpc/niobuf.c index a89b526..43b9db0 100644 --- a/lustre/ptlrpc/niobuf.c +++ b/lustre/ptlrpc/niobuf.c @@ -76,7 +76,7 @@ static int ptl_send_buf(struct lnet_handle_md *mdh, void *base, int len, ack = LNET_NOACK_REQ; } - rc = LNetMDBind (md, LNET_UNLINK, mdh); + rc = LNetMDBind(&md, LNET_UNLINK, mdh); if (unlikely(rc != 0)) { CERROR ("LNetMDBind failed: %d\n", rc); LASSERT (rc == -ENOMEM); @@ -208,7 +208,7 @@ int ptlrpc_start_bulk_transfer(struct ptlrpc_bulk_desc *desc) * page-aligned. Otherwise we'd have to send client bulk * sizes over and split server buffer accordingly */ ptlrpc_fill_bulk_md(&md, desc, posted_md); - rc = LNetMDBind(md, LNET_UNLINK, &desc->bd_mds[posted_md]); + rc = LNetMDBind(&md, LNET_UNLINK, &desc->bd_mds[posted_md]); if (rc != 0) { CERROR("%s: LNetMDBind failed for MD %u: rc = %d\n", exp->exp_obd->obd_name, posted_md, rc); @@ -393,7 +393,7 @@ int ptlrpc_register_bulk(struct ptlrpc_request *req) percpu_ref_get(&ptlrpc_pending); /* About to let the network at it... */ - rc = LNetMDAttach(me, md, LNET_UNLINK, + rc = LNetMDAttach(me, &md, LNET_UNLINK, &desc->bd_mds[posted_md]); if (rc != 0) { CERROR("%s: LNetMDAttach failed x%llu/%d: rc = %d\n", @@ -867,7 +867,7 @@ int ptl_send_rpc(struct ptlrpc_request *request, int noreply) /* We must see the unlink callback to set rq_reply_unlinked, * so we can't auto-unlink */ - rc = LNetMDAttach(reply_me, reply_md, LNET_RETAIN, + rc = LNetMDAttach(reply_me, &reply_md, LNET_RETAIN, &request->rq_reply_md_h); if (rc != 0) { CERROR("LNetMDAttach failed: %d\n", rc); @@ -991,7 +991,7 @@ int ptlrpc_register_rqbd(struct ptlrpc_request_buffer_desc *rqbd) md.user_ptr = &rqbd->rqbd_cbid; md.handler = ptlrpc_handler; - rc = LNetMDAttach(me, md, LNET_UNLINK, &rqbd->rqbd_md_h); + rc = LNetMDAttach(me, &md, LNET_UNLINK, &rqbd->rqbd_md_h); if (rc == 0) { percpu_ref_get(&ptlrpc_pending); return 0; -- 1.8.3.1