Whamcloud - gitweb
LU-8066 obd_type: discard obd_type_lock
[fs/lustre-release.git] / lustre / obdclass / genops.c
index bba84a9..436e5c7 100644 (file)
@@ -136,15 +136,17 @@ struct obd_type *class_get_type(const char *name)
         }
 #endif
         if (type) {
-               spin_lock(&type->obd_type_lock);
-               type->typ_refcnt++;
-               try_module_get(type->typ_dt_ops->o_owner);
-               spin_unlock(&type->obd_type_lock);
-               /* class_search_type() returned a counted reference,
-                * but we don't need that count any more as
-                * we have one through typ_refcnt.
-                */
-               kobject_put(&type->typ_kobj);
+               if (try_module_get(type->typ_dt_ops->o_owner)) {
+                       atomic_inc(&type->typ_refcnt);
+                       /* class_search_type() returned a counted reference,
+                        * but we don't need that count any more as
+                        * we have one through typ_refcnt.
+                        */
+                       kobject_put(&type->typ_kobj);
+               } else {
+                       kobject_put(&type->typ_kobj);
+                       type = NULL;
+               }
        }
        return type;
 }
@@ -152,10 +154,8 @@ struct obd_type *class_get_type(const char *name)
 void class_put_type(struct obd_type *type)
 {
        LASSERT(type);
-       spin_lock(&type->obd_type_lock);
-       type->typ_refcnt--;
        module_put(type->typ_dt_ops->o_owner);
-       spin_unlock(&type->obd_type_lock);
+       atomic_dec(&type->typ_refcnt);
 }
 
 static void class_sysfs_release(struct kobject *kobj)
@@ -276,7 +276,6 @@ dir_exist:
         /* md_ops is optional */
         if (md_ops)
                 *(type->typ_md_ops) = *md_ops;
-       spin_lock_init(&type->obd_type_lock);
 
 #ifdef HAVE_SERVER_SUPPORT
        if (type->typ_sym_filter) {
@@ -339,8 +338,9 @@ int class_unregister_type(const char *name)
                 RETURN(-EINVAL);
         }
 
-        if (type->typ_refcnt) {
-                CERROR("type %s has refcount (%d)\n", name, type->typ_refcnt);
+       if (atomic_read(&type->typ_refcnt)) {
+               CERROR("type %s has refcount (%d)\n", name,
+                      atomic_read(&type->typ_refcnt));
                 /* This is a bad situation, let's make the best of it */
                 /* Remove ops, but leave the name for debugging */
                 OBD_FREE_PTR(type->typ_dt_ops);