Commit 9c48768a authored by Ziye Yang's avatar Ziye Yang Committed by Changpeng Liu
Browse files

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: default avatarZiye Yang <ziye.yang@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/456580


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 3bf82af8
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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.