From 880cbc5da3f8041dd92cba31d5a8baa0c90049bc Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Thu, 9 May 2019 22:13:41 +0800 Subject: [PATCH] blobfs: fix the semphore usage issue in spdk_file_read We need to move sub_reads++ statement earlier. Otherwise if the read fails, the sem_wait(&channel->sem) call number is not correct. Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453788 (master) (cherry picked from commit bc1495b0f0270d7cbf7a9e64c1bea757b4056c9f) Change-Id: I05281a74bef78e4f80ce8d202b47849d1e6c2009 Signed-off-by: Tomasz Zawadzki Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457285 Reviewed-by: Ben Walker Reviewed-by: Darek Stojaczyk Tested-by: SPDK CI Jenkins --- lib/blobfs/blobfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index ecf165bb6..be646dae2 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -2456,6 +2456,8 @@ spdk_file_read(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, if (length > (final_offset - offset)) { length = final_offset - offset; } + + sub_reads++; rc = __file_read(file, payload, offset, length, channel); if (rc == 0) { final_length += length; @@ -2464,7 +2466,6 @@ spdk_file_read(struct spdk_file *file, struct spdk_fs_thread_ctx *ctx, } payload += length; offset += length; - sub_reads++; } pthread_spin_unlock(&file->lock); while (sub_reads-- > 0) {