From 83fd1929082ad643bff585a1f6dd52488b102b53 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Sun, 25 Feb 2024 18:41:46 -0500 Subject: [PATCH] LU-17022 obdclass: convert obd_conn_inprogress to atomic_t Using atomic_t for obd_conn_inprogress means we don't need to take a spinlock. Also send wakeup when value reaches zero, and wait for the wakeup instead of using a yield() loop. Change-Id: I9af29e068203cde951e592c408906d121702fa18 Signed-off-by: Mr NeilBrown Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51906 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day Reviewed-by: Arshad Hussain Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/obd.h | 2 +- lustre/ldlm/ldlm_lib.c | 17 ++++------------- lustre/obdclass/genops.c | 2 +- lustre/obdclass/obd_config.c | 4 ++-- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 9f38cff..774b151 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -740,7 +740,7 @@ struct obd_device { __u64 obd_pool_slv; int obd_pool_limit; - int obd_conn_inprogress; + atomic_t obd_conn_inprogress; /** * List of outstanding class_incref()'s fo this OBD. For debugging. */ diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index b2dd5d5..e480736 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -1121,13 +1121,9 @@ int target_handle_connect(struct ptlrpc_request *req) GOTO(out, rc = -ENODEV); } - spin_lock(&target->obd_dev_lock); - - target->obd_conn_inprogress++; + atomic_inc(&target->obd_conn_inprogress); if (target->obd_stopping || !target->obd_set_up) { - spin_unlock(&target->obd_dev_lock); - deuuidify(str, NULL, &target_start, &target_len); LCONSOLE_INFO("%.*s: Not available for connect from %s (%s)\n", target_len, target_start, @@ -1138,16 +1134,12 @@ int target_handle_connect(struct ptlrpc_request *req) } if (target->obd_no_conn) { - spin_unlock(&target->obd_dev_lock); - CDEBUG(D_INFO, "%s: Temporarily refusing client connection from %s\n", target->obd_name, libcfs_nidstr(&req->rq_peer.nid)); GOTO(out, rc = -EAGAIN); } - spin_unlock(&target->obd_dev_lock); - str = req_capsule_client_get(&req->rq_pill, &RMF_CLUUID); if (str == NULL) { DEBUG_REQ(D_ERROR, req, "bad client UUID for connect"); @@ -1624,10 +1616,9 @@ out: class_export_put(export); } - if (target != NULL) { - spin_lock(&target->obd_dev_lock); - target->obd_conn_inprogress--; - spin_unlock(&target->obd_dev_lock); + if (target) { + if (atomic_dec_and_test(&target->obd_conn_inprogress)) + wake_up_var(&target->obd_conn_inprogress); class_decref(target, "find", current); } if (pcon) diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 0118971..0607064 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -410,7 +410,7 @@ struct obd_device *class_newdev(const char *type_name, const char *name, lu_ref_init(&newdev->obd_reference); lu_ref_add(&newdev->obd_reference, "newdev", newdev); - newdev->obd_conn_inprogress = 0; + atomic_set(&newdev->obd_conn_inprogress, 0); strncpy(newdev->obd_uuid.uuid, uuid, UUID_MAX); diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index 89a5804..72947f8 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -846,8 +846,8 @@ int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg) spin_unlock(&obd->obd_dev_lock); /* wait for already-arrived-connections to finish. */ - while (obd->obd_conn_inprogress > 0) - yield(); + wait_var_event(&obd->obd_conn_inprogress, + atomic_read(&obd->obd_conn_inprogress) == 0); smp_rmb(); if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) { -- 1.8.3.1