}
#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;
}
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)
/* 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) {
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);
LASSERTF(type, "Server flags %d, obd %s\n", lsiflags,
obd ? obd->obd_name : "NULL");
- type_last = (type->typ_refcnt == 1);
+ type_last = (atomic_read(&type->typ_refcnt) == 1);
class_put_type(type);
if (obd != NULL && type_last) {
/* hold a type reference and put it at server_stop_servers */
type = class_get_type(IS_MDT(lsi) ?
LUSTRE_MDT_NAME : LUSTRE_OST_NAME);
+ if (!type) {
+ mutex_unlock(&server_start_lock);
+ GOTO(out_stop_service, rc = -ENODEV);
+ }
lsi->lsi_server_started = 1;
mutex_unlock(&server_start_lock);
if (OBD_FAIL_PRECHECK(OBD_FAIL_OBD_STOP_MDS_RACE) &&