From b1d50020c97cc66db5a6a506f20de1e1d733dacb Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 2 Mar 2020 19:59:43 -0500 Subject: [PATCH] LU-9859 ptlrpc: change imp_refcount to refcount_t The lustre portals handle was removed from the OBD import so it missed the move to refcount_t with the LU-12452 work. Moving to refcount_t also gives us security protection due to overflow issues with atomic_t. Lastly refcount_t gives use the same equivalent as LASSERT_ATOMIC_* with CONFIG_REFCOUNT_FULL thus allowing us to remove the LASSERT_ATOMIC_* wrappers in time. Change-Id: Ifdbd51c39bd3921e3f5d18d60efed6d1ff58c5c6 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/37733 Reviewed-by: Neil Brown Reviewed-by: Shaun Tancheff Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/include/lustre_import.h | 7 ++++++- lustre/obdclass/genops.c | 14 +++++++------- lustre/ptlrpc/import.c | 2 +- lustre/ptlrpc/pinger.c | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lustre/include/lustre_import.h b/lustre/include/lustre_import.h index 375d5ef..0dae5e7 100644 --- a/lustre/include/lustre_import.h +++ b/lustre/include/lustre_import.h @@ -45,6 +45,11 @@ #include #include #include +#ifdef HAVE_REFCOUNT_T +#include +#else +#include +#endif #include #include #include @@ -165,7 +170,7 @@ struct import_state_hist { */ struct obd_import { /** Reference counter */ - atomic_t imp_refcount; + refcount_t imp_refcount; struct lustre_handle imp_dlm_handle; /* client's ldlm export */ /** Currently active connection */ struct ptlrpc_connection *imp_connection; diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 23e72e6..f541c58 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -1175,7 +1175,7 @@ static void obd_zombie_import_free(struct obd_import *imp) CDEBUG(D_IOCTL, "destroying import %p for %s\n", imp, imp->imp_obd->obd_name); - LASSERT_ATOMIC_ZERO(&imp->imp_refcount); + LASSERT(refcount_read(&imp->imp_refcount) == 0); ptlrpc_put_connection_superhack(imp->imp_connection); @@ -1197,9 +1197,9 @@ static void obd_zombie_import_free(struct obd_import *imp) struct obd_import *class_import_get(struct obd_import *import) { - atomic_inc(&import->imp_refcount); + refcount_inc(&import->imp_refcount); CDEBUG(D_INFO, "import %p refcount=%d obd=%s\n", import, - atomic_read(&import->imp_refcount), + refcount_read(&import->imp_refcount), import->imp_obd->obd_name); return import; } @@ -1209,13 +1209,13 @@ void class_import_put(struct obd_import *imp) { ENTRY; - LASSERT_ATOMIC_GT_LT(&imp->imp_refcount, 0, LI_POISON); + LASSERT(refcount_read(&imp->imp_refcount) > 0); CDEBUG(D_INFO, "import %p refcount=%d obd=%s\n", imp, - atomic_read(&imp->imp_refcount) - 1, + refcount_read(&imp->imp_refcount) - 1, imp->imp_obd->obd_name); - if (atomic_dec_and_test(&imp->imp_refcount)) { + if (refcount_dec_and_test(&imp->imp_refcount)) { CDEBUG(D_INFO, "final put import %p\n", imp); obd_zombie_import_add(imp); } @@ -1274,7 +1274,7 @@ struct obd_import *class_new_import(struct obd_device *obd) else imp->imp_sec_refpid = 1; - atomic_set(&imp->imp_refcount, 2); + refcount_set(&imp->imp_refcount, 2); atomic_set(&imp->imp_unregistering, 0); atomic_set(&imp->imp_inflight, 0); atomic_set(&imp->imp_replay_inflight, 0); diff --git a/lustre/ptlrpc/import.c b/lustre/ptlrpc/import.c index 7977d59..1573efa 100644 --- a/lustre/ptlrpc/import.c +++ b/lustre/ptlrpc/import.c @@ -1768,7 +1768,7 @@ static int ptlrpc_disconnect_idle_interpret(const struct lu_env *env, DEBUG_REQ(D_HA, req, "inflight=%d, refcount=%d: rc = %d", atomic_read(&imp->imp_inflight), - atomic_read(&imp->imp_refcount), rc); + refcount_read(&imp->imp_refcount), rc); spin_lock(&imp->imp_lock); /* DISCONNECT reply can be late and another connection can just diff --git a/lustre/ptlrpc/pinger.c b/lustre/ptlrpc/pinger.c index 5b1133e..481b73b 100644 --- a/lustre/ptlrpc/pinger.c +++ b/lustre/ptlrpc/pinger.c @@ -108,7 +108,7 @@ static bool ptlrpc_check_import_is_idle(struct obd_import *imp) * - ptlrpcd_alloc_work() * - ptlrpc_pinger_add_import */ - if (atomic_read(&imp->imp_refcount) > 4) + if (refcount_read(&imp->imp_refcount) > 4) return false; /* any lock increases ns_bref being a resource holder */ -- 1.8.3.1