From eca2ee5c25412b2bed4f417a859009fd26e94b7f Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Mon, 31 Jul 2023 15:51:48 +0530 Subject: [PATCH] LU-16796 ptlrpc: Change struct lsi_mounts to use kref This patch changes struct lsi_mounts to use kref(refcount_t) instead of atomic_t Signed-off-by: Arshad Hussain Change-Id: Ia185b19123f535f8c54a6ea6b7a0212fbe85ffea Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51864 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Neil Brown Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/crypto/llcrypt.h | 4 ++-- libcfs/libcfs/crypto/keyring.c | 4 +--- lustre/include/lustre_disk.h | 2 +- lustre/obdclass/obd_mount.c | 41 +++++++++++++++++++--------------- lustre/target/tgt_mount.c | 6 ++--- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/libcfs/include/libcfs/crypto/llcrypt.h b/libcfs/include/libcfs/crypto/llcrypt.h index d05ff2a..246954e 100644 --- a/libcfs/include/libcfs/crypto/llcrypt.h +++ b/libcfs/include/libcfs/crypto/llcrypt.h @@ -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) { } diff --git a/libcfs/libcfs/crypto/keyring.c b/libcfs/libcfs/crypto/keyring.c index 358dda2..b053933 100644 --- a/libcfs/libcfs/crypto/keyring.c +++ b/libcfs/libcfs/crypto/keyring.c @@ -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; diff --git a/lustre/include/lustre_disk.h b/lustre/include/lustre_disk.h index 39f9864..99aff0d 100644 --- a/lustre/include/lustre_disk.h +++ b/lustre/include/lustre_disk.h @@ -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 */ diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 956997f..9487b68 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -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); diff --git a/lustre/target/tgt_mount.c b/lustre/target/tgt_mount.c index 2a312f2..29c8166 100644 --- a/lustre/target/tgt_mount.c +++ b/lustre/target/tgt_mount.c @@ -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", -- 1.8.3.1