From 83de606460b14b1ada27ded1f59956ffffe7d0b0 Mon Sep 17 00:00:00 2001 From: Patrick Farrell Date: Fri, 27 Oct 2023 14:42:41 -0400 Subject: [PATCH] EX-7601 ofd: round read lock to chunk For unaligned reads, we need to round the read locking to cover the any leading or trailing chunks. We do this by creating a local 'remote niobuf' to describe the rounded range and doing the locking against that niobuf. Signed-off-by: Patrick Farrell Change-Id: I8818522c188aca3c5c5eb564da2a8ba8aef18a4b Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52864 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Artem Blagodarenko Reviewed-by: Andreas Dilger --- lustre/target/tgt_handler.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lustre/target/tgt_handler.c b/lustre/target/tgt_handler.c index 68c555d..463ddb3 100644 --- a/lustre/target/tgt_handler.c +++ b/lustre/target/tgt_handler.c @@ -1774,6 +1774,8 @@ static int tgt_data_lock(const struct lu_env *env, struct obd_export *exp, struct ldlm_namespace *ns = exp->exp_obd->obd_namespace; __u64 flags = 0; + CDEBUG(D_INFO, "data locking [%llu, %llu)\n", start, end); + /* MDT IO for data-on-mdt */ if (exp->exp_connect_data.ocd_connect_flags & OBD_CONNECT_IBITS) return tgt_mdt_data_lock(ns, res_id, lh, mode, &flags); @@ -1789,11 +1791,10 @@ void tgt_data_unlock(struct lustre_handle *lh, enum ldlm_mode mode) EXPORT_SYMBOL(tgt_data_unlock); static int tgt_brw_lock(const struct lu_env *env, struct obd_export *exp, - struct ldlm_res_id *res_id, struct obd_ioobj *obj, - struct niobuf_remote *nb, struct lustre_handle *lh, - enum ldlm_mode mode) + struct ldlm_res_id *res_id, struct niobuf_remote *nb, + struct lustre_handle *lh, enum ldlm_mode mode, + int nrbufs) { - int nrbufs = obj->ioo_bufcnt; int i; ENTRY; @@ -2302,6 +2303,7 @@ int tgt_brw_read(struct tgt_session_info *tsi) struct tgt_thread_big_cache *tbc = req->rq_svc_thread->t_data; struct obd_export *exp = tsi->tsi_exp; struct lustre_handle lockh = { 0 }; + struct niobuf_remote chunk_lock_rnb; struct ptlrpc_bulk_desc *desc = NULL; struct niobuf_remote *remote_nb; struct niobuf_local *local_nb; @@ -2310,6 +2312,7 @@ int tgt_brw_read(struct tgt_session_info *tsi) struct obd_ioobj *ioo; struct ost_layout_compr *olc; const char *obd_name = exp->exp_obd->obd_name; + bool compr_rounded_read_lock = false; enum ll_compr_type type; int no_reply = 0; int npages_read; @@ -2411,12 +2414,19 @@ int tgt_brw_read(struct tgt_session_info *tsi) io_start, io_end, chunk_start, chunk_end); /* the start or end of this IO is unaligned */ - if (io_start != chunk_start || io_end != chunk_end) + if (io_start != chunk_start || io_end != chunk_end) { CDEBUG(D_SEC, "unaligned IO\n"); + chunk_lock_rnb.rnb_offset = chunk_start; + chunk_lock_rnb.rnb_len = chunk_end - chunk_start; + chunk_lock_rnb.rnb_flags = remote_nb[0].rnb_flags; + compr_rounded_read_lock = true; + } } - rc = tgt_brw_lock(tsi->tsi_env, exp, &tsi->tsi_resid, ioo, remote_nb, - &lockh, LCK_PR); + rc = tgt_brw_lock(tsi->tsi_env, exp, &tsi->tsi_resid, + compr_rounded_read_lock ? &chunk_lock_rnb : remote_nb, + &lockh, LCK_PR, + compr_rounded_read_lock ? 1 : ioo->ioo_bufcnt); if (rc != 0) RETURN(rc); @@ -2567,7 +2577,9 @@ out_commitrw: rc = obd_commitrw(tsi->tsi_env, OBD_BRW_READ, exp, &repbody->oa, 1, ioo, remote_nb, npages, local_nb, rc, nob, kstart); out_lock: - tgt_brw_unlock(exp, ioo, remote_nb, &lockh, LCK_PR); + tgt_brw_unlock(exp, ioo, + compr_rounded_read_lock ? &chunk_lock_rnb : remote_nb, + &lockh, LCK_PR); if (desc && !CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2)) ptlrpc_free_bulk(desc); @@ -2790,8 +2802,8 @@ int tgt_brw_write(struct tgt_session_info *tsi) local_nb = tbc->tbc_lnb; - rc = tgt_brw_lock(tsi->tsi_env, exp, &tsi->tsi_resid, ioo, remote_nb, - &lockh, LCK_PW); + rc = tgt_brw_lock(tsi->tsi_env, exp, &tsi->tsi_resid, remote_nb, &lockh, + LCK_PW, niocount); if (rc != 0) GOTO(out, rc); -- 1.8.3.1