[lustre-devel] [PATCH 13/15] lustre: obdclass: fix race in class_del_profile
James Simmons <[email protected]>
| Newsgroups | org.lustre.lists.lustre-devel |
|---|---|
| Message-ID | <[email protected]> |
From: Li Dongyang <[email protected]> Move profile lookup and remove from lustre_profile_list into the same critical section, otherwise we could race with class_del_profiles or another class_del_profile. Do not create duplicate mount opts in the client config, otherwise we will add duplicate lustre_profile to lustre_profile_list for a single mount. WC-bug-id: https://jira.whamcloud.com/browse/LU-15305 Lustre-commit: 83d3f42118579d7fb ("LU-15305 obdclass: fix race in class_del_profile") Signed-off-by: Li Dongyang <[email protected]> Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48802 Reviewed-by: Andreas Dilger <[email protected]> Reviewed-by: James Simmons <[email protected]> Reviewed-by: Oleg Drokin <[email protected]> Signed-off-by: James Simmons <[email protected]> --- fs/lustre/obdclass/obd_config.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/lustre/obdclass/obd_config.c b/fs/lustre/obdclass/obd_config.c index 2b24276..75fc6a6 100644 --- a/fs/lustre/obdclass/obd_config.c +++ b/fs/lustre/obdclass/obd_config.c @@ -622,21 +622,28 @@ static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg) static LIST_HEAD(lustre_profile_list); static DEFINE_SPINLOCK(lustre_profile_list_lock); -struct lustre_profile *class_get_profile(const char *prof) +static struct lustre_profile *class_get_profile_nolock(const char *prof) { struct lustre_profile *lprof; - spin_lock(&lustre_profile_list_lock); list_for_each_entry(lprof, &lustre_profile_list, lp_list) { - if (!strcmp(lprof->lp_profile, prof)) { + if (strcmp(lprof->lp_profile, prof) == 0) { lprof->lp_refs++; - spin_unlock(&lustre_profile_list_lock); return lprof; } } - spin_unlock(&lustre_profile_list_lock); return NULL; } + +struct lustre_profile *class_get_profile(const char *prof) +{ + struct lustre_profile *lprof; + + spin_lock(&lustre_profile_list_lock); + lprof = class_get_profile_nolock(prof); + spin_unlock(&lustre_profile_list_lock); + return lprof; +} EXPORT_SYMBOL(class_get_profile); /** Create a named "profile". @@ -701,9 +708,9 @@ void class_del_profile(const char *prof) CDEBUG(D_CONFIG, "Del profile %s\n", prof); - lprof = class_get_profile(prof); + spin_lock(&lustre_profile_list_lock); + lprof = class_get_profile_nolock(prof); if (lprof) { - spin_lock(&lustre_profile_list_lock); /* because get profile increments the ref counter */ lprof->lp_refs--; list_del(&lprof->lp_list); @@ -711,6 +718,8 @@ void class_del_profile(const char *prof) spin_unlock(&lustre_profile_list_lock); class_put_profile(lprof); + } else { + spin_unlock(&lustre_profile_list_lock); } } EXPORT_SYMBOL(class_del_profile); -- 1.8.3.1 _______________________________________________ lustre-devel mailing list [email protected] http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org