From 9c48768aa0d6599ef68057efe547aa9adfb328d4 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Mon, 3 Jun 2019 21:28:41 +0800 Subject: [PATCH] ut/blobfs: fix blobfs_sync_ut hang issue when testing file_length we use this statement: while (g_file->length_flushed != buf_length) {} in file_length function. It means that in this test case, length_flushed are accessed by two different threads, so better to use another new variable length_flused with volatile before the variable definition. Then our ut will not hang. Change-Id: I6152a4ba3f27f0fad1c8c2baa71324a36a2fb9e8 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/456580 Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Tested-by: SPDK CI Jenkins --- test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c b/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c index e70ea119a..285638e00 100644 --- a/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c +++ b/test/unit/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c @@ -237,6 +237,7 @@ file_length(void) int rc; char *buf; uint64_t buf_length; + volatile uint64_t *length_flushed; struct spdk_fs_thread_ctx *channel; struct spdk_file_stat stat = {0}; @@ -259,8 +260,13 @@ file_length(void) /* Spin until all of the data has been flushed to the SSD. There's been no * sync operation yet, so the xattr on the file is still 0. + * + * length_flushed: This variable is modified by a different thread in this unit + * test. So we need to dereference it as a volatile to ensure the value is always + * re-read. */ - while (g_file->length_flushed != buf_length) {} + length_flushed = &g_file->length_flushed; + while (*length_flushed != buf_length) {} /* Close the file. This causes an implicit sync which should write the * length_flushed value as the "length" xattr on the file.