Whamcloud - gitweb
LU-16796 ptlrpc: Change struct lsi_mounts to use kref 64/51864/4
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Mon, 31 Jul 2023 10:21:48 +0000 (15:51 +0530)
committerOleg Drokin <green@whamcloud.com>
Thu, 24 Aug 2023 04:35:41 +0000 (04:35 +0000)
This patch changes struct lsi_mounts to use
kref(refcount_t) instead of atomic_t

Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: Ia185b19123f535f8c54a6ea6b7a0212fbe85ffea
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51864
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/crypto/llcrypt.h
libcfs/libcfs/crypto/keyring.c
lustre/include/lustre_disk.h
lustre/obdclass/obd_mount.c
lustre/target/tgt_mount.c

index d05ff2a..246954e 100644 (file)
@@ -165,7 +165,7 @@ extern int llcrypt_inherit_context(struct inode *, struct inode *,
                                        void *, bool);
 extern bool llcrypt_policy_has_filename_enc(struct inode *inode);
 /* keyring.c */
-extern void llcrypt_sb_free(struct super_block *sb);
+extern void llcrypt_sb_free(struct lustre_sb_info *lsi);
 extern int llcrypt_ioctl_add_key(struct file *filp, void __user *arg);
 extern int llcrypt_ioctl_remove_key(struct file *filp, void __user *arg);
 extern int llcrypt_ioctl_remove_key_all_users(struct file *filp,
@@ -423,7 +423,7 @@ static inline bool llcrypt_policy_has_filename_enc(struct inode *inode)
 }
 
 /* keyring.c */
-static inline void llcrypt_sb_free(struct super_block *sb)
+static inline void llcrypt_sb_free(struct lustre_sb_info *lsi)
 {
 }
 
index 358dda2..b053933 100644 (file)
@@ -227,10 +227,8 @@ static int allocate_filesystem_keyring(struct super_block *sb)
        return 0;
 }
 
-void llcrypt_sb_free(struct super_block *sb)
+void llcrypt_sb_free(struct lustre_sb_info *lsi)
 {
-       struct lustre_sb_info *lsi = s2lsi(sb);
-
        if (lsi != NULL) {
                key_put(lsi->lsi_master_keys);
                lsi->lsi_master_keys = NULL;
index 39f9864..99aff0d 100644 (file)
@@ -143,7 +143,7 @@ struct lustre_sb_info {
        struct lustre_mount_data *lsi_lmd;     /* mount command info */
        struct ll_sb_info        *lsi_llsbi;   /* add'l client sbi info */
        struct dt_device         *lsi_dt_dev;  /* dt device to access disk fs*/
-       atomic_t                  lsi_mounts;  /* references to the srv_mnt */
+       struct kref               lsi_mounts;  /* references to the srv_mnt */
        struct kobject           *lsi_kobj;
        char                      lsi_svname[MTI_NAME_MAXLEN];
        /* lsi_osd_obdname format = 'lsi->ls_svname'-osd */
index 956997f..9487b68 100644 (file)
@@ -608,7 +608,7 @@ struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
 
        s2lsi_nocast(sb) = lsi;
        /* we take 1 extra ref for our setup */
-       atomic_set(&lsi->lsi_mounts, 1);
+       kref_init(&lsi->lsi_mounts);
 
        /* Default umount style */
        lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
@@ -619,19 +619,17 @@ struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
 }
 EXPORT_SYMBOL(lustre_init_lsi);
 
-static int lustre_free_lsi(struct super_block *sb)
+static int lustre_free_lsi(struct lustre_sb_info *lsi)
 {
-       struct lustre_sb_info *lsi = s2lsi(sb);
-
        ENTRY;
 
        LASSERT(lsi != NULL);
        CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
 
        /* someone didn't call server_put_mount. */
-       LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
+       LASSERT(kref_read(&lsi->lsi_mounts) == 0);
 
-       llcrypt_sb_free(sb);
+       llcrypt_sb_free(lsi);
        if (lsi->lsi_lmd != NULL) {
                if (lsi->lsi_lmd->lmd_dev != NULL)
                        OBD_FREE(lsi->lsi_lmd->lmd_dev,
@@ -669,11 +667,26 @@ static int lustre_free_lsi(struct super_block *sb)
 
        LASSERT(lsi->lsi_llsbi == NULL);
        OBD_FREE_PTR(lsi);
-       s2lsi_nocast(sb) = NULL;
 
        RETURN(0);
 }
 
+static void lustre_put_lsi_free(struct kref *kref)
+{
+       struct lustre_sb_info *lsi = container_of(kref, struct lustre_sb_info,
+                                                 lsi_mounts);
+
+       if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
+               lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
+               lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
+               lsi->lsi_dt_dev = NULL;
+               obd_disconnect(lsi->lsi_osd_exp);
+               /* wait till OSD is gone */
+               obd_zombie_barrier();
+       }
+       lustre_free_lsi(lsi);
+}
+
 /*
  * The lsi has one reference for every server that is using the disk -
  * e.g. MDT, MGS, and potentially MGC
@@ -686,17 +699,9 @@ int lustre_put_lsi(struct super_block *sb)
 
        LASSERT(lsi != NULL);
 
-       CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
-       if (atomic_dec_and_test(&lsi->lsi_mounts)) {
-               if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
-                       lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
-                       lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
-                       lsi->lsi_dt_dev = NULL;
-                       obd_disconnect(lsi->lsi_osd_exp);
-                       /* wait till OSD is gone */
-                       obd_zombie_barrier();
-               }
-               lustre_free_lsi(sb);
+       CDEBUG(D_MOUNT, "put %p %d\n", sb, kref_read(&lsi->lsi_mounts));
+       if (kref_put(&lsi->lsi_mounts, lustre_put_lsi_free)) {
+               s2lsi_nocast(sb) = NULL;
                RETURN(1);
        }
        RETURN(0);
index 2a312f2..29c8166 100644 (file)
@@ -162,10 +162,10 @@ struct lustre_mount_info *server_get_mount(const char *name)
        }
        lsi = s2lsi(lmi->lmi_sb);
 
-       atomic_inc(&lsi->lsi_mounts);
+       kref_get(&lsi->lsi_mounts);
 
        CDEBUG(D_MOUNT, "get mount %p from %s, refs=%d\n", lmi->lmi_sb,
-              name, atomic_read(&lsi->lsi_mounts));
+              name, kref_read(&lsi->lsi_mounts));
 
        RETURN(lmi);
 }
@@ -199,7 +199,7 @@ int server_put_mount(const char *name, bool dereg_mnt)
        lsi = s2lsi(lmi->lmi_sb);
 
        CDEBUG(D_MOUNT, "put mount %p from %s, refs=%d\n",
-              lmi->lmi_sb, name, atomic_read(&lsi->lsi_mounts));
+              lmi->lmi_sb, name, kref_read(&lsi->lsi_mounts));
 
        if (lustre_put_lsi(lmi->lmi_sb))
                CDEBUG(D_MOUNT, "Last put of mount %p from %s\n",