}
#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);
atomic_read(&obd->obd_refcount));
}
read_unlock(&obd_dev_lock);
- return;
}
/* Search for a client OBD connected to tgt_uuid. If grp_uuid is
struct obd_device *obd = exp->exp_obd;
ENTRY;
- LASSERT_ATOMIC_ZERO(&exp->exp_refcount);
+ LASSERT(refcount_read(&exp->exp_handle.h_ref) == 0);
LASSERT(obd != NULL);
CDEBUG(D_IOCTL, "destroying export %p/%s for %s\n", exp,
EXIT;
}
-static void export_handle_addref(void *export)
-{
- class_export_get(export);
-}
-
static struct portals_handle_ops export_handle_ops = {
- .hop_addref = export_handle_addref,
.hop_free = NULL,
+ .hop_type = "export",
};
struct obd_export *class_export_get(struct obd_export *exp)
{
- atomic_inc(&exp->exp_refcount);
- CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp,
- atomic_read(&exp->exp_refcount));
+ refcount_inc(&exp->exp_handle.h_ref);
+ CDEBUG(D_INFO, "GET export %p refcount=%d\n", exp,
+ refcount_read(&exp->exp_handle.h_ref));
return exp;
}
EXPORT_SYMBOL(class_export_get);
void class_export_put(struct obd_export *exp)
{
LASSERT(exp != NULL);
- LASSERT_ATOMIC_GT_LT(&exp->exp_refcount, 0, LI_POISON);
+ LASSERT(refcount_read(&exp->exp_handle.h_ref) > 0);
+ LASSERT(refcount_read(&exp->exp_handle.h_ref) < LI_POISON);
CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", exp,
- atomic_read(&exp->exp_refcount) - 1);
+ refcount_read(&exp->exp_handle.h_ref) - 1);
- if (atomic_dec_and_test(&exp->exp_refcount)) {
+ if (refcount_dec_and_test(&exp->exp_handle.h_ref)) {
struct obd_device *obd = exp->exp_obd;
CDEBUG(D_IOCTL, "final put %p/%s\n",
export->exp_lock_hash = NULL;
export->exp_flock_hash = NULL;
/* 2 = class_handle_hash + last */
- atomic_set(&export->exp_refcount, 2);
+ refcount_set(&export->exp_handle.h_ref, 2);
atomic_set(&export->exp_rpc_count, 0);
atomic_set(&export->exp_cb_count, 0);
atomic_set(&export->exp_locks_count, 0);
CDEBUG(debug_level, "%s: %s %p %s %s %d (%d %d %d) %d %d %d %d: "
"%p %s %llu stale:%d\n",
exp->exp_obd->obd_name, status, exp, exp->exp_client_uuid.uuid,
- obd_export_nid2str(exp), atomic_read(&exp->exp_refcount),
+ obd_export_nid2str(exp),
+ refcount_read(&exp->exp_handle.h_ref),
atomic_read(&exp->exp_rpc_count),
atomic_read(&exp->exp_cb_count),
atomic_read(&exp->exp_locks_count),
__u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
struct lookup_intent *it)
{
- struct l_wait_info lwi = LWI_INTR(NULL, NULL);
bool close_req = false;
__u16 i, max;
"opc %u, max %hu\n",
cli->cl_import->imp_obd->obd_name, opc, max);
- l_wait_event_exclusive(cli->cl_mod_rpcs_waitq,
- obd_mod_rpc_slot_avail(cli, close_req),
- &lwi);
+ wait_event_idle_exclusive(cli->cl_mod_rpcs_waitq,
+ obd_mod_rpc_slot_avail(cli,
+ close_req));
} while (true);
}
EXPORT_SYMBOL(obd_get_mod_rpc_slot);