Skip to content

Commit b213a8f

Browse files
committed
Add fatal conditions for locked chunks
1 parent 65264f4 commit b213a8f

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

worker.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -759,15 +759,23 @@ DWORD ChunkDiskWorker::CloseChunkAsync(const u64 chunk_idx, const bool is_write,
759759
// reply WAIT_CHUNK to the locking worker
760760
auto err = [this, chunk_idx]() -> DWORD
761761
{
762-
auto msg = ChunkWork();
763-
auto err = PrepareMsg(msg, WAIT_CHUNK, chunk_idx);
764-
if (err != ERROR_SUCCESS) return err;
765-
766762
auto* user = LPVOID();
767763
service_.CheckChunkLocked(chunk_idx, user);
768-
if (user == nullptr) return ERROR_INVALID_STATE;
764+
if (user == nullptr)
765+
{
766+
SpdStorageUnitShutdown(service_.storage_unit); // fatal
767+
return ERROR_INVALID_STATE;
768+
}
769769
auto* worker = recast<ChunkDiskWorker*>(recast<ChunkOpState*>(user)->ovl.hEvent);
770-
if (worker == nullptr) return ERROR_INVALID_STATE;
770+
if (worker == nullptr)
771+
{
772+
SpdStorageUnitShutdown(service_.storage_unit); // fatal
773+
return ERROR_INVALID_STATE;
774+
}
775+
776+
auto msg = ChunkWork();
777+
auto err = PrepareMsg(msg, WAIT_CHUNK, chunk_idx);
778+
if (err != ERROR_SUCCESS) return err;
771779
err = worker->PostMsg(std::move(msg));
772780
return err == ERROR_IO_PENDING ? ERROR_SUCCESS : err;
773781
}();
@@ -814,15 +822,23 @@ DWORD ChunkDiskWorker::LockChunk(const u64 chunk_idx)
814822
lk.unlock();
815823
auto err = [this, chunk_idx]() -> DWORD
816824
{
817-
auto msg = ChunkWork();
818-
auto err = PrepareMsg(msg, WAIT_CHUNK, chunk_idx);
819-
if (err != ERROR_SUCCESS) return err;
820-
821825
auto* user = LPVOID();
822826
service_.CheckChunkLocked(chunk_idx, user);
823-
if (user == nullptr) return ERROR_INVALID_STATE;
827+
if (user == nullptr)
828+
{
829+
SpdStorageUnitShutdown(service_.storage_unit); // fatal
830+
return ERROR_INVALID_STATE;
831+
}
824832
auto* worker = recast<ChunkDiskWorker*>(recast<ChunkOpState*>(user)->ovl.hEvent);
825-
if (worker == nullptr) return ERROR_INVALID_STATE;
833+
if (worker == nullptr)
834+
{
835+
SpdStorageUnitShutdown(service_.storage_unit); // fatal
836+
return ERROR_INVALID_STATE;
837+
}
838+
839+
auto msg = ChunkWork();
840+
auto err = PrepareMsg(msg, WAIT_CHUNK, chunk_idx);
841+
if (err != ERROR_SUCCESS) return err;
826842
err = worker->PostMsg(std::move(msg));
827843
return err == ERROR_IO_PENDING ? ERROR_SUCCESS : err;
828844
}();

0 commit comments

Comments
 (0)