Whamcloud - gitweb
LU-9859 ptlrpc: change imp_refcount to refcount_t 33/37733/4
authorJames Simmons <jsimmons@infradead.org>
Tue, 3 Mar 2020 00:59:43 +0000 (19:59 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 11 Mar 2020 02:19:49 +0000 (02:19 +0000)
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 <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/37733
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_import.h
lustre/obdclass/genops.c
lustre/ptlrpc/import.c
lustre/ptlrpc/pinger.c

index 375d5ef..0dae5e7 100644 (file)
 #include <linux/atomic.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
+#ifdef HAVE_REFCOUNT_T
+#include <linux/refcount.h>
+#else
+#include <libcfs/linux/linux-refcount.h>
+#endif
 #include <linux/spinlock.h>
 #include <linux/time.h>
 #include <linux/types.h>
@@ -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;
index 23e72e6..f541c58 100644 (file)
@@ -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);
index 7977d59..1573efa 100644 (file)
@@ -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
index 5b1133e..481b73b 100644 (file)
@@ -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 */