X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdclass%2Fgenops.c;h=436e5c76d11fd93b4a18c61931af8e10c660e622;hb=6722a95fd0416fa6f24140130ea8a1e0df5f1542;hp=bba84a9a9e34c0fe15244290bedb3041447e61c4;hpb=fafb52290c675e36b09d1de88cdd65ba981cb3a0;p=fs%2Flustre-release.git diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index bba84a9..436e5c7 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -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);