This patch changes struct obd_device to use
kref(refcount_t) instead of atomic_t
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: Ia8539abb11357b41edd4cf532896d3bc1e66e92f
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52179
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
struct list_head obd_unlinked_exports;
struct list_head obd_delayed_exports;
struct list_head obd_lwp_list;
struct list_head obd_unlinked_exports;
struct list_head obd_delayed_exports;
struct list_head obd_lwp_list;
+ struct kref obd_refcount;
int obd_num_exports;
int obd_grant_check_threshold;
spinlock_t obd_nid_lock;
int obd_num_exports;
int obd_grant_check_threshold;
spinlock_t obd_nid_lock;
CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
- atomic_read(&obd->obd_refcount));
+ kref_read(&obd->obd_refcount));
lmv_statfs_check_update(obd, tgt);
lmv_statfs_check_update(obd, tgt);
snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
index, status, obd->obd_type->typ_name,
obd->obd_name, obd->obd_uuid.uuid,
snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
index, status, obd->obd_type->typ_name,
obd->obd_name, obd->obd_uuid.uuid,
- atomic_read(&obd->obd_refcount));
+ kref_read(&obd->obd_refcount));
if (copy_to_user(uarg, data, len))
rc = -EFAULT;
if (copy_to_user(uarg, data, len))
rc = -EFAULT;
llog_group_init(&newdev->obd_olg);
/* Detach drops this */
llog_group_init(&newdev->obd_olg);
/* Detach drops this */
- atomic_set(&newdev->obd_refcount, 1);
+ kref_init(&newdev->obd_refcount);
lu_ref_init(&newdev->obd_reference);
lu_ref_add(&newdev->obd_reference, "newdev", newdev);
lu_ref_init(&newdev->obd_reference);
lu_ref_add(&newdev->obd_reference, "newdev", newdev);
LASSERTF(obd->obd_minor == -1 || obd_devs[obd->obd_minor] == obd,
"obd %p != obd_devs[%d] %p\n",
obd, obd->obd_minor, obd_devs[obd->obd_minor]);
LASSERTF(obd->obd_minor == -1 || obd_devs[obd->obd_minor] == obd,
"obd %p != obd_devs[%d] %p\n",
obd, obd->obd_minor, obd_devs[obd->obd_minor]);
- LASSERTF(atomic_read(&obd->obd_refcount) == 0,
+ LASSERTF(kref_read(&obd->obd_refcount) == 0,
"obd_refcount should be 0, not %d\n",
"obd_refcount should be 0, not %d\n",
- atomic_read(&obd->obd_refcount));
+ kref_read(&obd->obd_refcount));
LASSERT(obd_type != NULL);
CDEBUG(D_INFO, "Release obd device %s obd_type name = %s\n",
LASSERT(obd_type != NULL);
CDEBUG(D_INFO, "Release obd device %s obd_type name = %s\n",
LCONSOLE(D_CONFIG, "%3d %s %s %s %s %d\n",
i, status, obd->obd_type->typ_name,
obd->obd_name, obd->obd_uuid.uuid,
LCONSOLE(D_CONFIG, "%3d %s %s %s %s %d\n",
i, status, obd->obd_type->typ_name,
obd->obd_name, obd->obd_uuid.uuid,
- atomic_read(&obd->obd_refcount));
+ kref_read(&obd->obd_refcount));
}
read_unlock(&obd_dev_lock);
}
}
read_unlock(&obd_dev_lock);
}
"more than %d seconds. "
"The obd refcount = %d. Is it stuck?\n",
obd->obd_name, waited,
"more than %d seconds. "
"The obd refcount = %d. Is it stuck?\n",
obd->obd_name, waited,
- atomic_read(&obd->obd_refcount));
+ kref_read(&obd->obd_refcount));
dump_exports(obd, 1, D_CONSOLE | D_WARNING);
}
waited *= 2;
dump_exports(obd, 1, D_CONSOLE | D_WARNING);
}
waited *= 2;
obd->obd_uuid.uuid);
nla_put_u32(msg, LUSTRE_DEVICE_ATTR_REFCOUNT,
obd->obd_uuid.uuid);
nla_put_u32(msg, LUSTRE_DEVICE_ATTR_REFCOUNT,
- atomic_read(&obd->obd_refcount));
+ kref_read(&obd->obd_refcount));
obd->obd_attached = 1;
CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
obd->obd_attached = 1;
CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
- obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
+ obd->obd_minor, typename, kref_read(&obd->obd_refcount));
CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d/%d\n",
obd->obd_name, obd->obd_num_exports,
CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d/%d\n",
obd->obd_name, obd->obd_num_exports,
- atomic_read(&obd->obd_refcount) - 2);
+ kref_read(&obd->obd_refcount) - 2);
dump_exports(obd, 0, D_HA);
class_disconnect_exports(obd);
dump_exports(obd, 0, D_HA);
class_disconnect_exports(obd);
const void *source)
{
lu_ref_add_atomic(&obd->obd_reference, scope, source);
const void *source)
{
lu_ref_add_atomic(&obd->obd_reference, scope, source);
- atomic_inc(&obd->obd_refcount);
+ kref_get(&obd->obd_refcount);
CDEBUG(D_INFO, "incref %s (%p) now %d - %s\n", obd->obd_name, obd,
CDEBUG(D_INFO, "incref %s (%p) now %d - %s\n", obd->obd_name, obd,
- atomic_read(&obd->obd_refcount), scope);
+ kref_read(&obd->obd_refcount), scope);
return obd;
}
EXPORT_SYMBOL(class_incref);
return obd;
}
EXPORT_SYMBOL(class_incref);
-void class_decref(struct obd_device *obd, const char *scope, const void *source)
+static void class_decref_free(struct kref *kref)
+ struct obd_device *obd;
+ struct obd_export *exp;
- CDEBUG(D_INFO, "Decref %s (%p) now %d - %s\n", obd->obd_name, obd,
- atomic_read(&obd->obd_refcount), scope);
+ obd = container_of(kref, struct obd_device, obd_refcount);
+ LASSERT(!obd->obd_attached);
+ /*
+ * All exports have been destroyed; there should
+ * be no more in-progress ops by this point.
+ */
+ exp = obd->obd_self_export;
+ if (exp) {
+ exp->exp_flags |= exp_flags_from_obd(obd);
+ class_unlink_export(exp);
+ }
+}
+
+void class_decref(struct obd_device *obd, const char *scope, const void *source)
+{
+ CDEBUG(D_INFO, "Decref %s (%p) now %d - %s\n", obd->obd_name, obd,
+ kref_read(&obd->obd_refcount), scope);
LASSERT(obd->obd_num_exports >= 0);
LASSERT(obd->obd_num_exports >= 0);
- last = atomic_dec_and_test(&obd->obd_refcount);
+ kref_put(&obd->obd_refcount, class_decref_free);
lu_ref_del(&obd->obd_reference, scope, source);
lu_ref_del(&obd->obd_reference, scope, source);
-
- if (last) {
- struct obd_export *exp;
-
- LASSERT(!obd->obd_attached);
- /*
- * All exports have been destroyed; there should
- * be no more in-progress ops by this point.
- */
- exp = obd->obd_self_export;
-
- if (exp) {
- exp->exp_flags |= exp_flags_from_obd(obd);
- class_unlink_export(exp);
- }
- }
}
EXPORT_SYMBOL(class_decref);
}
EXPORT_SYMBOL(class_decref);
seq_printf(p, "%3d %s %s %s %s %d\n",
(int)index, status, obd->obd_type->typ_name,
obd->obd_name, obd->obd_uuid.uuid,
seq_printf(p, "%3d %s %s %s %s %d\n",
(int)index, status, obd->obd_type->typ_name,
obd->obd_name, obd->obd_uuid.uuid,
- atomic_read(&obd->obd_refcount));
+ kref_read(&obd->obd_refcount));