[lustre-devel] [PATCH 35/49] lustre: obdclass: Protect cl_env_percpu[]

James Simmons jsimmons at infradead.org
Wed Apr 14 21:02:27 PDT 2021


From: Etienne AUJAMES <eaujames at ddn.com>

cl_env_percpu is not protected against multi client mounts on the
same node: "keys_fill" could be called with the same cl_env_percpu
context by several mount processes (race on lu_context.lc_value).

This patch add a mutex for cl_env_percpu to proctect contexts
"refill".

WC-bug-id: https://jira.whamcloud.com/browse/LU-14110
Lustre-commit: 881551fbb733569 ("LU-14110 obdclass: Protect cl_env_percpu[]")
Signed-off-by: Etienne AUJAMES <eaujames at ddn.com>
Reviewed-on: https://review.whamcloud.com/40565
Reviewed-by: Neil Brown <neilb at suse.de>
Reviewed-by: Andreas Dilger <adilger at whamcloud.com>
Reviewed-by: James Simmons <jsimmons at infradead.org>
Reviewed-by: Oleg Drokin <green at whamcloud.com>
Signed-off-by: James Simmons <jsimmons at infradead.org>
---
 fs/lustre/include/obd_support.h | 1 +
 fs/lustre/llite/llite_lib.c     | 2 ++
 fs/lustre/obdclass/cl_object.c  | 3 +++
 3 files changed, 6 insertions(+)

diff --git a/fs/lustre/include/obd_support.h b/fs/lustre/include/obd_support.h
index b2f97f1..027667f 100644
--- a/fs/lustre/include/obd_support.h
+++ b/fs/lustre/include/obd_support.h
@@ -477,6 +477,7 @@
 #define OBD_FAIL_LLITE_PCC_ATTACH_PAUSE			0x1414
 #define OBD_FAIL_LLITE_SHORT_COMMIT			0x1415
 #define OBD_FAIL_LLITE_CREATE_FILE_PAUSE2		0x1416
+#define OBD_FAIL_LLITE_RACE_MOUNT			0x1417
 
 #define OBD_FAIL_FID_INDIR				0x1501
 #define OBD_FAIL_FID_INLMA				0x1502
diff --git a/fs/lustre/llite/llite_lib.c b/fs/lustre/llite/llite_lib.c
index e15962e..2f2d9f0 100644
--- a/fs/lustre/llite/llite_lib.c
+++ b/fs/lustre/llite/llite_lib.c
@@ -1047,6 +1047,8 @@ int ll_fill_super(struct super_block *sb)
 
 	CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
 
+	OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
+
 	cfg = kzalloc(sizeof(*cfg), GFP_NOFS);
 	if (!cfg) {
 		err = -ENOMEM;
diff --git a/fs/lustre/obdclass/cl_object.c b/fs/lustre/obdclass/cl_object.c
index 86434f1..aa3d928 100644
--- a/fs/lustre/obdclass/cl_object.c
+++ b/fs/lustre/obdclass/cl_object.c
@@ -823,6 +823,7 @@ void cl_lvb2attr(struct cl_attr *attr, const struct ost_lvb *lvb)
 EXPORT_SYMBOL(cl_lvb2attr);
 
 static struct cl_env cl_env_percpu[NR_CPUS];
+static DEFINE_MUTEX(cl_env_percpu_mutex);
 
 static int cl_env_percpu_init(void)
 {
@@ -888,8 +889,10 @@ static void cl_env_percpu_refill(void)
 {
 	int i;
 
+	mutex_lock(&cl_env_percpu_mutex);
 	for_each_possible_cpu(i)
 		lu_env_refill(&cl_env_percpu[i].ce_lu);
+	mutex_unlock(&cl_env_percpu_mutex);
 }
 
 void cl_env_percpu_put(struct lu_env *env)
-- 
1.8.3.1



More information about the lustre-devel mailing list