From 9becfb0f26e67335ef05292eb663471173bf76e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Tue, 12 Aug 2025 16:40:16 +0800 Subject: [PATCH 1/5] exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 3 + interfaces/kits/hyperaio/src/hyperaio.cpp | 109 +++++++++++++------- 2 files changed, 77 insertions(+), 35 deletions(-) diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h index f7f64104c..111d0f2ad 100644 --- a/interfaces/kits/hyperaio/include/hyperaio.h +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -97,6 +97,9 @@ private: std::atomic stopThread_ = true; std::atomic initialized_ = false; void HarvestRes(); + void HandleError(std::vector &errorVec); + void HandleSqeError(uint32_t count, std::vector &infoVec, std::vector &errorVec); + int32_t CheckParameter(uint32_t reqNum); }; } } diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 1f5dc006d..d8607bd73 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -114,30 +114,70 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) return EOK; } -int32_t HyperAio::StartOpenReqs(OpenReqs *req) +void HyperAio::HandleError(std::vector &errorVec) { - if (pImpl_ == nullptr) { - return -EINVAL; + HILOGI("into HandleError"); + for (auto &userdata : errorVec) { + HILOGI("HandleError: userData = %{public}lu", userdata); + auto response = std::make_unique(userdata, -EBUSY, 0); + ioResultCallBack_(std::move(response)); } - if (req == nullptr || req->reqs == nullptr) { + errorVec.clear(); +} + +void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec, std::vector &errorVec) +{ + if (count > 0) { + int32_t ret = io_uring_submit(&pImpl_->uring_); + if (ret < 0) { + HILOGE("submit read reqs failed, ret = %{public}d", ret); + HandleError(infoVec); + } + readReqCount_+= count; + } + HandleError(errorVec); +} + +int32_t HyperAio::CheckParameter(uint32_t reqNum) +{ + if (pImpl_ == nullptr) { return -EINVAL; } if (!initialized_.load()) { HILOGE("HyperAio is not initialized"); return -EPERM; } - if (!ValidateReqNum(req->reqNum)) { - HILOGE("reqNum is out of range: %{public}u", req->reqNum); + if (!ValidateReqNum(reqNum)) { + HILOGE("reqNum is out of range: %{public}u", reqNum); return -EINVAL; } + return EOK; +} + +int32_t HyperAio::StartOpenReqs(OpenReqs *req) +{ + + if (req == nullptr || req->reqs == nullptr) { + return -EINVAL; + } + int32_t ret = CheckParameter(req->reqNum); + if (ret < 0) { + return ret; + } + HyperaioTrace trace("StartOpenReqs" + std::to_string(req->reqNum)); uint32_t totalReqs = req->reqNum; uint32_t count = 0; + std::vector errorVec; + std::vector openInfoVec; for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { - HILOGE("get sqe failed"); - return -ENOMEM; + for (uint32_t j = i; j < totalReqs; ++j) { + errorVec.push_back(req->reqs[j].userData); + } + HandleSqeError(count, openInfoVec, errorVec); + break; } struct OpenInfo *openInfo = &req->reqs[i]; io_uring_sqe_set_data(sqe, reinterpret_cast(openInfo->userData)); @@ -148,11 +188,12 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) HyperaioTrace trace("open flags:" + std::to_string(openInfo->flags) + "mode:" + std::to_string(openInfo->mode) + "userData:" + std::to_string(openInfo->userData)); count++; + openInfoVec.push_back(openInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit open reqs failed, ret = %{public}d", ret); - return ret; + HandleError(openInfoVec); } openReqCount_ += count; count = 0; @@ -163,28 +204,26 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) int32_t HyperAio::StartReadReqs(ReadReqs *req) { - if (pImpl_ == nullptr) { - return -EINVAL; - } if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } - if (!initialized_.load()) { - HILOGE("HyperAio is not initialized"); - return -EPERM; - } - if (!ValidateReqNum(req->reqNum)) { - HILOGE("reqNum is out of range: %{public}u", req->reqNum); - return -EINVAL; + int32_t ret = CheckParameter(req->reqNum); + if (ret < 0) { + return ret; } HyperaioTrace trace("StartReadReqs" + std::to_string(req->reqNum)); uint32_t totalReqs = req->reqNum; uint32_t count = 0; + std::vector errorVec; + std::vector readInfoVec; for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { - HILOGE("get sqe failed"); - return -ENOMEM; + for (uint32_t j = i; j < totalReqs; ++j) { + errorVec.push_back(req->reqs[j].userData); + } + HandleSqeError(count, readInfoVec, errorVec); + break; } struct ReadInfo *readInfo = &req->reqs[i]; io_uring_sqe_set_data(sqe, reinterpret_cast(readInfo->userData)); @@ -194,11 +233,12 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) HyperaioTrace trace("read len:" + std::to_string(readInfo->len) + "offset:" + std::to_string(readInfo->offset) + "userData:" + std::to_string(readInfo->userData)); count++; + readInfoVec.push_back(readInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit read reqs failed, ret = %{public}d", ret); - return ret; + HandleError(readInfoVec); } readReqCount_ += count; count = 0; @@ -209,28 +249,26 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) int32_t HyperAio::StartCancelReqs(CancelReqs *req) { - if (pImpl_ == nullptr) { - return -EINVAL; - } if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } - if (!initialized_.load()) { - HILOGE("HyperAio is not initialized"); - return -EPERM; - } - if (!ValidateReqNum(req->reqNum)) { - HILOGE("reqNum is out of range: %{public}u", req->reqNum); - return -EINVAL; + int32_t ret = CheckParameter(req->reqNum); + if (ret < 0) { + return ret; } HyperaioTrace trace("StartCancelReqs" + std::to_string(req->reqNum)); uint32_t totalReqs = req->reqNum; uint32_t count = 0; + std::vector errorVec; + std::vector cancelInfoVec; for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { - HILOGE("get sqe failed"); - return -ENOMEM; + for (uint32_t j = i; j < totalReqs; ++j) { + errorVec.push_back(req->reqs[j].userData); + } + HandleSqeError(count, cancelInfoVec, errorVec); + break; } struct CancelInfo *cancelInfo = &req->reqs[i]; io_uring_sqe_set_data(sqe, reinterpret_cast(cancelInfo->userData)); @@ -240,11 +278,12 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) HyperaioTrace trace("cancel userData:" + std::to_string(cancelInfo->userData) + "targetUserData:" + std::to_string(cancelInfo->targetUserData)); count++; + cancelInfoVec.push_back(cancelInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit cancel reqs failed, ret = %{public}d", ret); - return ret; + HandleError(cancelInfoVec); } cancelReqCount_ += count; count = 0; -- Gitee From ebf11012985c3726752f0f90601cda49916a69f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Tue, 12 Aug 2025 16:49:22 +0800 Subject: [PATCH 2/5] exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index d8607bd73..451b4917d 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -133,7 +133,7 @@ void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec, st HILOGE("submit read reqs failed, ret = %{public}d", ret); HandleError(infoVec); } - readReqCount_+= count; + readReqCount_ += count; } HandleError(errorVec); } -- Gitee From cecbdea25781821a8fddc2139d423930d0897b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Tue, 12 Aug 2025 18:54:30 +0800 Subject: [PATCH 3/5] exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 1 - interfaces/test/unittest/hyperaio/hyperaio_test.cpp | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 451b4917d..dbf1c1dc6 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -156,7 +156,6 @@ int32_t HyperAio::CheckParameter(uint32_t reqNum) int32_t HyperAio::StartOpenReqs(OpenReqs *req) { - if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index b1916adbd..7d249bcc1 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -240,7 +240,7 @@ namespace OHOS::HyperAio { EXPECT_EQ(result, 0); sqe_flag = false; result = hyperAio_->StartOpenReqs(&openReqs); - EXPECT_EQ(result, -ENOMEM); + EXPECT_EQ(result, 0); sqe_flag = true; result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); @@ -381,7 +381,7 @@ namespace OHOS::HyperAio { EXPECT_EQ(result, 0); sqe_flag = false; result = hyperAio_->StartReadReqs(&readReqs); - EXPECT_EQ(result, -ENOMEM); + EXPECT_EQ(result, 0); sqe_flag = true; result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); @@ -518,7 +518,7 @@ namespace OHOS::HyperAio { EXPECT_EQ(result, 0); sqe_flag = false; result = hyperAio_->StartCancelReqs(&cancelReqs); - EXPECT_EQ(result, -ENOMEM); + EXPECT_EQ(result, 0); sqe_flag = true; result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); -- Gitee From ceca3eb6c5641ba7d0183dd36520297fdf4fe427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Wed, 13 Aug 2025 15:03:20 +0800 Subject: [PATCH 4/5] exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../test/unittest/hyperaio/hyperaio_test.cpp | 15 +++++++++++++++ .../test/unittest/hyperaio/include/liburing.h | 13 +++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index 7d249bcc1..b22587c43 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -242,6 +242,11 @@ namespace OHOS::HyperAio { result = hyperAio_->StartOpenReqs(&openReqs); EXPECT_EQ(result, 0); sqe_flag = true; + submit_flag = false; + sqe_probability = 100; + result = hyperAio_->StartOpenReqs(&openReqs); + EXPECT_EQ(result, 0); + submit_flag = true; result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0003"; @@ -269,6 +274,7 @@ namespace OHOS::HyperAio { openInfos[i].userData = userData + i; } OpenReqs openReqs = {Threshold, openInfos.get()}; + sqe_probability = 100; result = hyperAio_->StartOpenReqs(&openReqs); EXPECT_EQ(result, -EINVAL); result = hyperAio_->DestroyCtx(); @@ -377,12 +383,17 @@ namespace OHOS::HyperAio { readInfos[i].userData = userData + i; } ReadReqs readReqs = {batchSize, readInfos.get()}; + sqe_probability = 100; result = hyperAio_->StartReadReqs(&readReqs); EXPECT_EQ(result, 0); sqe_flag = false; result = hyperAio_->StartReadReqs(&readReqs); EXPECT_EQ(result, 0); sqe_flag = true; + submit_flag = false; + result = hyperAio_->StartReadReqs(&readReqs); + EXPECT_EQ(result, 0); + submit_flag = true; result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0003"; @@ -520,6 +531,10 @@ namespace OHOS::HyperAio { result = hyperAio_->StartCancelReqs(&cancelReqs); EXPECT_EQ(result, 0); sqe_flag = true; + submit_flag = false; + result = hyperAio_->StartCancelReqs(&cancelReqs); + EXPECT_EQ(result, 0); + submit_flag = true; result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0003"; diff --git a/interfaces/test/unittest/hyperaio/include/liburing.h b/interfaces/test/unittest/hyperaio/include/liburing.h index b00112be3..a75e74b79 100644 --- a/interfaces/test/unittest/hyperaio/include/liburing.h +++ b/interfaces/test/unittest/hyperaio/include/liburing.h @@ -17,6 +17,8 @@ #define UNITTEST_HYPERAIO_INCLUDE_LIBURING_H #include +#include +#include #include namespace OHOS { namespace HyperAio { @@ -25,6 +27,8 @@ inline bool sqe_flag = true; inline bool init_flag = true; inline bool wait_flag = true; inline bool cqe_res_flag = true; +inline bool submit_flag = true; +inline int sqe_probability = 100; struct io_uring_sqe { int32_t data; }; @@ -55,7 +59,9 @@ struct io_uring { inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring) { - if (sqe_flag) { + srand(static_cast(time(NULL))); + if (sqe_flag && rand() % 100 < sqe_probability) { + sqe_probability = (sqe_probability > 0) ? sqe_probability - 1 : 0; return ring->io_uring_get_sqe(); } return nullptr; @@ -63,7 +69,10 @@ inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring) inline int io_uring_submit(struct io_uring *ring) { - return 1; + if (submit_flag) { + return 1; + } + return -1; } inline int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags) -- Gitee From f7b017507815376710cbc69a8db56f5af09006d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Wed, 13 Aug 2025 15:12:54 +0800 Subject: [PATCH 5/5] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index dbf1c1dc6..9a5f1521c 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -116,6 +116,9 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) void HyperAio::HandleError(std::vector &errorVec) { + if (errorVec.empty()) { + return; + } HILOGI("into HandleError"); for (auto &userdata : errorVec) { HILOGI("HandleError: userData = %{public}lu", userdata); @@ -159,6 +162,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } + int32_t ret = CheckParameter(req->reqNum); if (ret < 0) { return ret; @@ -206,6 +210,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } + int32_t ret = CheckParameter(req->reqNum); if (ret < 0) { return ret; @@ -251,6 +256,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } + int32_t ret = CheckParameter(req->reqNum); if (ret < 0) { return ret; -- Gitee