Whamcloud - gitweb
LU-16796 obd: Change struct obd_device to use kref 79/52179/2
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Wed, 30 Aug 2023 09:39:58 +0000 (15:09 +0530)
committerOleg Drokin <green@whamcloud.com>
Wed, 13 Sep 2023 04:06:45 +0000 (04:06 +0000)
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>
lustre/include/obd.h
lustre/lmv/lmv_obd.c
lustre/obdclass/class_obd.c
lustre/obdclass/genops.c
lustre/obdclass/kernelcomm.c
lustre/obdclass/obd_config.c
lustre/obdclass/obd_sysfs.c

index 10c3006..8b41f8b 100644 (file)
@@ -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;
        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;
        int                     obd_num_exports;
        int                     obd_grant_check_threshold;
        spinlock_t              obd_nid_lock;
index 3be890b..2bebb98 100644 (file)
@@ -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,
 
        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);
 
index bf33208..8a1165e 100644 (file)
@@ -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,
                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;
index b037a14..879080b 100644 (file)
@@ -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 */
 
        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);
 
@@ -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(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",
@@ -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,
                 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);
 }
@@ -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,
                                      "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;
index b8198b1..fd86b93 100644 (file)
@@ -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,
                               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);
        }
 
                genlmsg_end(msg, hdr);
        }
index d9e0e62..2498c7a 100644 (file)
@@ -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_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);
 }
 
        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,
 
        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);
 
@@ -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);
                                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)
 {
 {
-       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);
        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);
 
index d6a9a51..05c9f60 100644 (file)
@@ -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,
        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;
 }
 
        return 0;
 }