From de1c549814cdf5b9989f29b754cb0f94860b1223 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Wed, 30 Aug 2023 15:09:58 +0530 Subject: [PATCH] LU-16796 obd: Change struct obd_device to use kref This patch changes struct obd_device to use kref(refcount_t) instead of atomic_t Signed-off-by: Arshad Hussain Change-Id: Ia8539abb11357b41edd4cf532896d3bc1e66e92f Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52179 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Patrick Farrell Reviewed-by: Neil Brown Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/obd.h | 2 +- lustre/lmv/lmv_obd.c | 2 +- lustre/obdclass/class_obd.c | 2 +- lustre/obdclass/genops.c | 10 ++++----- lustre/obdclass/kernelcomm.c | 2 +- lustre/obdclass/obd_config.c | 50 ++++++++++++++++++++++---------------------- lustre/obdclass/obd_sysfs.c | 2 +- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 10c3006..8b41f8b 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -653,7 +653,7 @@ struct obd_device { struct list_head obd_unlinked_exports; struct list_head obd_delayed_exports; struct list_head obd_lwp_list; - atomic_t obd_refcount; + struct kref obd_refcount; int obd_num_exports; int obd_grant_check_threshold; spinlock_t obd_nid_lock; diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 3be890b..2bebb98 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -355,7 +355,7 @@ static int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt) 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); diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index bf33208..8a1165e 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -474,7 +474,7 @@ int class_handle_ioctl(unsigned int cmd, void __user *uarg) 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; diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index b037a14..879080b 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -406,7 +406,7 @@ struct obd_device *class_newdev(const char *type_name, const char *name, 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); @@ -436,9 +436,9 @@ void class_free_dev(struct obd_device *obd) 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", - 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", @@ -742,7 +742,7 @@ void class_obd_list(void) 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); } @@ -1794,7 +1794,7 @@ void obd_exports_barrier(struct obd_device *obd) "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; diff --git a/lustre/obdclass/kernelcomm.c b/lustre/obdclass/kernelcomm.c index b8198b1..fd86b93 100644 --- a/lustre/obdclass/kernelcomm.c +++ b/lustre/obdclass/kernelcomm.c @@ -251,7 +251,7 @@ static int lustre_device_list_dump(struct sk_buff *msg, obd->obd_uuid.uuid); nla_put_u32(msg, LUSTRE_DEVICE_ATTR_REFCOUNT, - atomic_read(&obd->obd_refcount)); + kref_read(&obd->obd_refcount)); genlmsg_end(msg, hdr); } diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index d9e0e62..2498c7a 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -653,7 +653,7 @@ int class_attach(struct lustre_cfg *lcfg) 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)); RETURN(0); } @@ -882,7 +882,7 @@ int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg) 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); @@ -922,40 +922,40 @@ struct obd_device *class_incref(struct obd_device *obd, 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, - atomic_read(&obd->obd_refcount), scope); + kref_read(&obd->obd_refcount), scope); 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) { - int last; + 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); - last = atomic_dec_and_test(&obd->obd_refcount); + kref_put(&obd->obd_refcount, class_decref_free); 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); diff --git a/lustre/obdclass/obd_sysfs.c b/lustre/obdclass/obd_sysfs.c index d6a9a51..05c9f60 100644 --- a/lustre/obdclass/obd_sysfs.c +++ b/lustre/obdclass/obd_sysfs.c @@ -502,7 +502,7 @@ static int obd_device_list_seq_show(struct seq_file *p, void *v) 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)); return 0; } -- 1.8.3.1