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 01/21] 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 02/21] 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 03/21] 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 04/21] 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 05/21] 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 From e5d2085f5da0380e71b8b1fc22a2a71c36c8425f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Wed, 13 Aug 2025 16:43:05 +0800 Subject: [PATCH 06/21] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/test/unittest/hyperaio/hyperaio_test.cpp | 3 --- interfaces/test/unittest/hyperaio/include/liburing.h | 9 +++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index b22587c43..0aa3de24b 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -243,7 +243,6 @@ namespace OHOS::HyperAio { EXPECT_EQ(result, 0); sqe_flag = true; submit_flag = false; - sqe_probability = 100; result = hyperAio_->StartOpenReqs(&openReqs); EXPECT_EQ(result, 0); submit_flag = true; @@ -274,7 +273,6 @@ 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(); @@ -383,7 +381,6 @@ 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; diff --git a/interfaces/test/unittest/hyperaio/include/liburing.h b/interfaces/test/unittest/hyperaio/include/liburing.h index a75e74b79..e5b53ba35 100644 --- a/interfaces/test/unittest/hyperaio/include/liburing.h +++ b/interfaces/test/unittest/hyperaio/include/liburing.h @@ -17,8 +17,6 @@ #define UNITTEST_HYPERAIO_INCLUDE_LIBURING_H #include -#include -#include #include namespace OHOS { namespace HyperAio { @@ -28,7 +26,6 @@ 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; }; @@ -59,9 +56,8 @@ struct io_uring { inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring) { - srand(static_cast(time(NULL))); - if (sqe_flag && rand() % 100 < sqe_probability) { - sqe_probability = (sqe_probability > 0) ? sqe_probability - 1 : 0; + if (sqe_flag) { + sqe_flag = !sqe_flag; return ring->io_uring_get_sqe(); } return nullptr; @@ -77,6 +73,7 @@ inline int io_uring_submit(struct io_uring *ring) inline int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags) { + sqe_flag = true; if (init_flag) { return 1; } -- Gitee From daa6d46deefd4d695095dc1b57b4dd3bab0c8597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 14 Aug 2025 09:11:00 +0800 Subject: [PATCH 07/21] 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, 5 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 9a5f1521c..4665cea37 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -144,6 +144,7 @@ void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec, st int32_t HyperAio::CheckParameter(uint32_t reqNum) { if (pImpl_ == nullptr) { + HILOGE("pImpl is not initialized"); return -EINVAL; } if (!initialized_.load()) { @@ -160,6 +161,7 @@ int32_t HyperAio::CheckParameter(uint32_t reqNum) int32_t HyperAio::StartOpenReqs(OpenReqs *req) { if (req == nullptr || req->reqs == nullptr) { + HILOGE("the request is empty"); return -EINVAL; } @@ -208,6 +210,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) int32_t HyperAio::StartReadReqs(ReadReqs *req) { if (req == nullptr || req->reqs == nullptr) { + HILOGE("the request is empty"); return -EINVAL; } @@ -254,9 +257,10 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) int32_t HyperAio::StartCancelReqs(CancelReqs *req) { if (req == nullptr || req->reqs == nullptr) { + HILOGE("the request is empty"); return -EINVAL; } - + int32_t ret = CheckParameter(req->reqNum); if (ret < 0) { return ret; -- Gitee From 4502a261bfae189d16983ab650362d43673ea7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 14 Aug 2025 10:36:50 +0800 Subject: [PATCH 08/21] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 2 +- interfaces/kits/hyperaio/src/hyperaio.cpp | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h index 111d0f2ad..8905ccc7b 100644 --- a/interfaces/kits/hyperaio/include/hyperaio.h +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -97,7 +97,7 @@ private: std::atomic stopThread_ = true; std::atomic initialized_ = false; void HarvestRes(); - void HandleError(std::vector &errorVec); + void CallbackError(std::vector &errorVec, int32_t errorcode); 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 4665cea37..ec3ece2e3 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -114,15 +114,15 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) return EOK; } -void HyperAio::HandleError(std::vector &errorVec) +void HyperAio::CallbackError(std::vector &errorVec, int32_t errorcode) { if (errorVec.empty()) { + HILOGE("errorVec is empty"); return; } - HILOGI("into HandleError"); for (auto &userdata : errorVec) { - HILOGI("HandleError: userData = %{public}lu", userdata); - auto response = std::make_unique(userdata, -EBUSY, 0); + HILOGE("CallbackError: userData = %{public}lu", userdata); + auto response = std::make_unique(userdata, errorcode, 0); ioResultCallBack_(std::move(response)); } errorVec.clear(); @@ -134,11 +134,11 @@ void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec, st int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit read reqs failed, ret = %{public}d", ret); - HandleError(infoVec); + CallbackError(infoVec, -EBUSY); } readReqCount_ += count; } - HandleError(errorVec); + CallbackError(errorVec, -ENOMEN); } int32_t HyperAio::CheckParameter(uint32_t reqNum) @@ -178,6 +178,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { + HILOGE("get sqe failed"); for (uint32_t j = i; j < totalReqs; ++j) { errorVec.push_back(req->reqs[j].userData); } @@ -198,7 +199,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit open reqs failed, ret = %{public}d", ret); - HandleError(openInfoVec); + CallbackError(openInfoVec, -EBUSY); } openReqCount_ += count; count = 0; @@ -245,7 +246,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit read reqs failed, ret = %{public}d", ret); - HandleError(readInfoVec); + CallbackError(readInfoVec, -EBUSY); } readReqCount_ += count; count = 0; @@ -292,7 +293,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit cancel reqs failed, ret = %{public}d", ret); - HandleError(cancelInfoVec); + CallbackError(cancelInfoVec, -EBUSY); } cancelReqCount_ += count; count = 0; -- Gitee From a113f72416a124696e86bd0c88c4a080ef07847e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 14 Aug 2025 16:07:13 +0800 Subject: [PATCH 09/21] 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index ec3ece2e3..9019e2613 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -227,6 +227,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { + HILOGE("get sqe failed"); for (uint32_t j = i; j < totalReqs; ++j) { errorVec.push_back(req->reqs[j].userData); } @@ -274,6 +275,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { + HILOGE("get sqe failed"); for (uint32_t j = i; j < totalReqs; ++j) { errorVec.push_back(req->reqs[j].userData); } -- Gitee From 822e1baddb30527b4e90c6cf98d6218d43afcd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 14 Aug 2025 20:49:03 +0800 Subject: [PATCH 10/21] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 2 +- interfaces/kits/hyperaio/src/hyperaio.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h index 8905ccc7b..aa9a07692 100644 --- a/interfaces/kits/hyperaio/include/hyperaio.h +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -98,7 +98,7 @@ private: std::atomic initialized_ = false; void HarvestRes(); void CallbackError(std::vector &errorVec, int32_t errorcode); - void HandleSqeError(uint32_t count, std::vector &infoVec, std::vector &errorVec); + void HandleSqeError(uint32_t count, std::vector &infoVec); int32_t CheckParameter(uint32_t reqNum); }; } diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 9019e2613..a9aca57b8 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -128,7 +128,7 @@ void HyperAio::CallbackError(std::vector &errorVec, int32_t errorcode) errorVec.clear(); } -void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec, std::vector &errorVec) +void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec) { if (count > 0) { int32_t ret = io_uring_submit(&pImpl_->uring_); @@ -138,7 +138,6 @@ void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec, st } readReqCount_ += count; } - CallbackError(errorVec, -ENOMEN); } int32_t HyperAio::CheckParameter(uint32_t reqNum) @@ -182,7 +181,8 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) for (uint32_t j = i; j < totalReqs; ++j) { errorVec.push_back(req->reqs[j].userData); } - HandleSqeError(count, openInfoVec, errorVec); + HandleSqeError(count, openInfoVec); + CallbackError(errorVec, -EBUSY); break; } struct OpenInfo *openInfo = &req->reqs[i]; @@ -231,7 +231,8 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) for (uint32_t j = i; j < totalReqs; ++j) { errorVec.push_back(req->reqs[j].userData); } - HandleSqeError(count, readInfoVec, errorVec); + HandleSqeError(count, readInfoVec); + CallbackError(errorVec, -EBUSY); break; } struct ReadInfo *readInfo = &req->reqs[i]; @@ -279,7 +280,8 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) for (uint32_t j = i; j < totalReqs; ++j) { errorVec.push_back(req->reqs[j].userData); } - HandleSqeError(count, cancelInfoVec, errorVec); + HandleSqeError(count, cancelInfoVec); + CallbackError(errorVec, -EBUSY); break; } struct CancelInfo *cancelInfo = &req->reqs[i]; -- Gitee From 98ab9bf337f489fe32fe14f53c88ae7296cb8b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 14 Aug 2025 22:40:46 +0800 Subject: [PATCH 11/21] 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 | 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 a9aca57b8..81ebff151 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -134,7 +134,7 @@ void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec) int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit read reqs failed, ret = %{public}d", ret); - CallbackError(infoVec, -EBUSY); + CallbackError(infoVec, ret); } readReqCount_ += count; } -- Gitee From 893a5a95e2311d5d433a529c2b7d15200fd824a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 14 Aug 2025 23:06:52 +0800 Subject: [PATCH 12/21] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 2 +- interfaces/kits/hyperaio/src/hyperaio.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h index aa9a07692..d13b9ef9b 100644 --- a/interfaces/kits/hyperaio/include/hyperaio.h +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -97,7 +97,7 @@ private: std::atomic stopThread_ = true; std::atomic initialized_ = false; void HarvestRes(); - void CallbackError(std::vector &errorVec, int32_t errorcode); + void HandleRequestError(std::vector &errorVec, int32_t errorcode); void HandleSqeError(uint32_t count, std::vector &infoVec); int32_t CheckParameter(uint32_t reqNum); }; diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 81ebff151..a8c605828 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -114,14 +114,14 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) return EOK; } -void HyperAio::CallbackError(std::vector &errorVec, int32_t errorcode) +void HyperAio::HandleRequestError(std::vector &errorVec, int32_t errorcode) { if (errorVec.empty()) { HILOGE("errorVec is empty"); return; } for (auto &userdata : errorVec) { - HILOGE("CallbackError: userData = %{public}lu", userdata); + HILOGE("HandleRequestError: userData = %{public}lu", userdata); auto response = std::make_unique(userdata, errorcode, 0); ioResultCallBack_(std::move(response)); } @@ -134,7 +134,7 @@ void HyperAio::HandleSqeError(uint32_t count, std::vector &infoVec) int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit read reqs failed, ret = %{public}d", ret); - CallbackError(infoVec, ret); + HandleRequestError(infoVec, ret); } readReqCount_ += count; } @@ -182,7 +182,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) errorVec.push_back(req->reqs[j].userData); } HandleSqeError(count, openInfoVec); - CallbackError(errorVec, -EBUSY); + HandleRequestError(errorVec, -EBUSY); break; } struct OpenInfo *openInfo = &req->reqs[i]; @@ -199,7 +199,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit open reqs failed, ret = %{public}d", ret); - CallbackError(openInfoVec, -EBUSY); + HandleRequestError(openInfoVec, -EBUSY); } openReqCount_ += count; count = 0; @@ -232,7 +232,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) errorVec.push_back(req->reqs[j].userData); } HandleSqeError(count, readInfoVec); - CallbackError(errorVec, -EBUSY); + HandleRequestError(errorVec, -EBUSY); break; } struct ReadInfo *readInfo = &req->reqs[i]; @@ -248,7 +248,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit read reqs failed, ret = %{public}d", ret); - CallbackError(readInfoVec, -EBUSY); + HandleRequestError(readInfoVec, -EBUSY); } readReqCount_ += count; count = 0; @@ -281,7 +281,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) errorVec.push_back(req->reqs[j].userData); } HandleSqeError(count, cancelInfoVec); - CallbackError(errorVec, -EBUSY); + HandleRequestError(errorVec, -EBUSY); break; } struct CancelInfo *cancelInfo = &req->reqs[i]; @@ -297,7 +297,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit cancel reqs failed, ret = %{public}d", ret); - CallbackError(cancelInfoVec, -EBUSY); + HandleRequestError(cancelInfoVec, -EBUSY); } cancelReqCount_ += count; count = 0; -- Gitee From fc44d6bbf2eeed02c871238f8305282192b9db63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 15 Aug 2025 16:07:42 +0800 Subject: [PATCH 13/21] 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 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index a8c605828..c2a2ded0f 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -178,8 +178,8 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); - for (uint32_t j = i; j < totalReqs; ++j) { - errorVec.push_back(req->reqs[j].userData); + for (; i < totalReqs; ++i) { + errorVec.push_back(req->reqs[i].userData); } HandleSqeError(count, openInfoVec); HandleRequestError(errorVec, -EBUSY); @@ -228,8 +228,8 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); - for (uint32_t j = i; j < totalReqs; ++j) { - errorVec.push_back(req->reqs[j].userData); + for (; i < totalReqs; ++i) { + errorVec.push_back(req->reqs[i].userData); } HandleSqeError(count, readInfoVec); HandleRequestError(errorVec, -EBUSY); @@ -277,8 +277,8 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); - for (uint32_t j = i; j < totalReqs; ++j) { - errorVec.push_back(req->reqs[j].userData); + for (; i < totalReqs; ++i) { + errorVec.push_back(req->reqs[i].userData); } HandleSqeError(count, cancelInfoVec); HandleRequestError(errorVec, -EBUSY); -- Gitee From 1c236f0bcf43088d7c8fd57a1d122fb149da86ab Mon Sep 17 00:00:00 2001 From: wcj Date: Mon, 18 Aug 2025 19:18:09 +0800 Subject: [PATCH 14/21] =?UTF-8?q?1.1=20new=E5=88=86=E9=85=8D=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=97=B6=E5=BC=82=E5=B8=B8=E5=9C=BA=E6=99=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuchengjun Change-Id: Ie77fde0b37d9ffee621ea1595f66c27afa1f9362 --- .../randomaccessfile_n_exporter.cpp | 2 +- .../kits/js/src/mod_fs/properties/close.cpp | 2 +- .../properties/create_randomaccessfile.cpp | 8 ++++++-- .../kits/js/src/mod_fs/properties/fdatasync.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/fsync.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/mkdtemp.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/movedir.cpp | 2 +- .../kits/js/src/mod_fs/properties/open.cpp | 2 +- .../js/src/mod_fs/properties/prop_n_exporter.cpp | 16 ++++++++-------- .../kits/js/src/mod_fs/properties/read_text.cpp | 14 +++++++++----- .../kits/js/src/mod_fs/properties/rename.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/symlink.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/truncate.cpp | 6 +++--- .../kits/js/src/mod_fs/properties/utimes.cpp | 2 +- 14 files changed, 41 insertions(+), 33 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp index 4a2350c68..b13d1a2ed 100644 --- a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp @@ -357,7 +357,7 @@ napi_value RandomAccessFileNExporter::Write(napi_env env, napi_callback_info inf static NError CloseFd(int fd) { std::unique_ptr close_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!close_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/close.cpp b/interfaces/kits/js/src/mod_fs/properties/close.cpp index 0ca2fe8e5..d0aea72a5 100755 --- a/interfaces/kits/js/src/mod_fs/properties/close.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close.cpp @@ -45,7 +45,7 @@ static FileEntity *GetFileEntity(napi_env env, napi_value objFile) static NError CloseFd(int fd) { std::unique_ptr close_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!close_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/create_randomaccessfile.cpp b/interfaces/kits/js/src/mod_fs/properties/create_randomaccessfile.cpp index 3d7672b47..2c04155dd 100644 --- a/interfaces/kits/js/src/mod_fs/properties/create_randomaccessfile.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/create_randomaccessfile.cpp @@ -185,7 +185,7 @@ napi_value CreateRandomAccessFile::Sync(napi_env env, napi_callback_info info) return nullptr; } std::unique_ptr open_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!open_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -218,7 +218,11 @@ NError AsyncExec(shared_ptr arg, { if (fileInfo->isPath) { std::unique_ptr open_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; + if (!open_req) { + HILOGE("Failed to request heap memory."); + return NError(ENOMEM); + } int ret = uv_fs_open(nullptr, open_req.get(), fileInfo->path.get(), flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, NULL); if (ret < 0) { diff --git a/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp b/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp index 94ace2d8e..05eed610e 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fdatasync.cpp @@ -45,7 +45,7 @@ napi_value Fdatasync::Sync(napi_env env, napi_callback_info info) } std::unique_ptr fdatasync_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!fdatasync_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -79,7 +79,7 @@ napi_value Fdatasync::Async(napi_env env, napi_callback_info info) auto cbExec = [fd = fd]() -> NError { std::unique_ptr fdatasync_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!fdatasync_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/fsync.cpp b/interfaces/kits/js/src/mod_fs/properties/fsync.cpp index a475546e0..a5bccb922 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fsync.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fsync.cpp @@ -43,7 +43,7 @@ napi_value Fsync::Sync(napi_env env, napi_callback_info info) } std::unique_ptr fsync_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!fsync_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -76,7 +76,7 @@ napi_value Fsync::Async(napi_env env, napi_callback_info info) auto cbExec = [fd = fd]() -> NError { std::unique_ptr fsync_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!fsync_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp b/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp index c304e4a67..a61d9e78e 100755 --- a/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/mkdtemp.cpp @@ -43,7 +43,7 @@ napi_value Mkdtemp::Sync(napi_env env, napi_callback_info info) string path = tmp.get(); std::unique_ptr mkdtemp_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!mkdtemp_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -62,7 +62,7 @@ napi_value Mkdtemp::Sync(napi_env env, napi_callback_info info) static NError MkdTempExec(shared_ptr arg, const string &path) { std::unique_ptr mkdtemp_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!mkdtemp_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index 31eee911c..f8b41ba9c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -210,7 +210,7 @@ static int RecurMoveDir(const string &srcPath, const string &destPath, const int return ERRNO_NOERR; } - unique_ptr ptr = {new struct NameListArg, Deleter}; + unique_ptr ptr = {new (std::nothrow) struct NameListArg, Deleter}; if (!ptr) { HILOGE("Failed to request heap memory."); return ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index 7b5280059..c9b3d2c99 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -136,7 +136,7 @@ static NVal InstantiateFile(napi_env env, int fd, string pathOrUri, bool isUri, static int OpenFileByPath(const string &path, unsigned int mode) { unique_ptr open_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!open_req) { HILOGE("Failed to request heap memory."); return -ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index 74502ebf6..c7b6c9c60 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -104,7 +104,7 @@ struct AccessArgs { static int UvAccess(const string &path, int mode) { - std::unique_ptr access_req = {new uv_fs_t, + std::unique_ptr access_req = {new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup}; if (!access_req) { HILOGE("Failed to request heap memory."); @@ -338,7 +338,7 @@ napi_value PropNExporter::Unlink(napi_env env, napi_callback_info info) auto cbExec = [path = string(tmp.get())]() -> NError { std::unique_ptr unlink_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!unlink_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); @@ -384,7 +384,7 @@ napi_value PropNExporter::UnlinkSync(napi_env env, napi_callback_info info) } std::unique_ptr unlink_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!unlink_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -403,7 +403,7 @@ napi_value PropNExporter::UnlinkSync(napi_env env, napi_callback_info info) static int MkdirCore(const string &path) { std::unique_ptr mkdir_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!mkdir_req) { HILOGE("Failed to request heap memory."); return ENOMEM; @@ -562,7 +562,7 @@ napi_value PropNExporter::ReadSync(napi_env env, napi_callback_info info) uv_buf_t buffer = uv_buf_init(static_cast(buf), static_cast(len)); std::unique_ptr read_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!read_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -582,7 +582,7 @@ static NError ReadExec(shared_ptr arg, char *buf, size_t len, in { uv_buf_t buffer = uv_buf_init(buf, len); std::unique_ptr read_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!read_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); @@ -660,7 +660,7 @@ static NError WriteExec(shared_ptr arg, char *buf, size_t len, { uv_buf_t buffer = uv_buf_init(buf, static_cast(len)); std::unique_ptr write_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!write_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); @@ -762,7 +762,7 @@ napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info) uv_buf_t buffer = uv_buf_init(static_cast(buf), static_cast(len)); std::unique_ptr write_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!write_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); diff --git a/interfaces/kits/js/src/mod_fs/properties/read_text.cpp b/interfaces/kits/js/src/mod_fs/properties/read_text.cpp index d77d5601a..bdbd14375 100755 --- a/interfaces/kits/js/src/mod_fs/properties/read_text.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_text.cpp @@ -37,7 +37,11 @@ static tuple> GetReadTextArg(na int64_t len = 0; bool succ = false; bool hasLen = false; - unique_ptr encoding { new char[]{ "utf-8" } }; + unique_ptr encoding { new (std::nothrow) char[]{ "utf-8" } }; + if(!encoding){ + HILOGE("Failed to request heap memory."); + return { false, offset, hasLen, len, nullptr }; + } if (op.HasProp("offset") && !op.GetProp("offset").TypeIs(napi_undefined)) { tie(succ, offset) = op.GetProp("offset").ToInt64(); @@ -74,7 +78,7 @@ static NError ReadTextAsync(const std::string &path, std::shared_ptr open_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!open_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); @@ -105,7 +109,7 @@ static NError ReadTextAsync(const std::string &path, std::shared_ptr(buffer.c_str()), static_cast(len)); std::unique_ptr read_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!read_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); @@ -122,7 +126,7 @@ static NError ReadTextAsync(const std::string &path, std::shared_ptr open_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (open_req == nullptr) { HILOGE("Failed to request heap memory."); @@ -137,7 +141,7 @@ static int ReadFromFile(int fd, int64_t offset, string& buffer) { uv_buf_t readbuf = uv_buf_init(const_cast(buffer.c_str()), static_cast(buffer.size())); std::unique_ptr read_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (read_req == nullptr) { HILOGE("Failed to request heap memory."); return -ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/rename.cpp b/interfaces/kits/js/src/mod_fs/properties/rename.cpp index c71258c94..620f032a7 100755 --- a/interfaces/kits/js/src/mod_fs/properties/rename.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/rename.cpp @@ -52,7 +52,7 @@ napi_value Rename::Sync(napi_env env, napi_callback_info info) } std::unique_ptr rename_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!rename_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -93,7 +93,7 @@ napi_value Rename::Async(napi_env env, napi_callback_info info) auto cbExec = [opath = string(src.get()), npath = string(dest.get())]() -> NError { std::unique_ptr rename_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!rename_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/symlink.cpp b/interfaces/kits/js/src/mod_fs/properties/symlink.cpp index a83e8e187..49e73d31a 100755 --- a/interfaces/kits/js/src/mod_fs/properties/symlink.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/symlink.cpp @@ -61,7 +61,7 @@ napi_value Symlink::Sync(napi_env env, napi_callback_info info) } std::unique_ptr symlink_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!symlink_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -95,7 +95,7 @@ napi_value Symlink::Async(napi_env env, napi_callback_info info) auto cbExec = [oldPath = move(oldPath), newPath = move(newPath)]() -> NError { std::unique_ptr symlink_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!symlink_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/truncate.cpp b/interfaces/kits/js/src/mod_fs/properties/truncate.cpp index 1fafa81d0..acefbf6d5 100644 --- a/interfaces/kits/js/src/mod_fs/properties/truncate.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/truncate.cpp @@ -53,7 +53,7 @@ static NError TruncateCore(napi_env env, FileInfo &fileInfo, int64_t truncateLen { if (fileInfo.isPath) { std::unique_ptr open_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!open_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); @@ -66,7 +66,7 @@ static NError TruncateCore(napi_env env, FileInfo &fileInfo, int64_t truncateLen } FDGuard fd(ret); std::unique_ptr ftruncate_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!ftruncate_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); @@ -78,7 +78,7 @@ static NError TruncateCore(napi_env env, FileInfo &fileInfo, int64_t truncateLen } } else { std::unique_ptr ftruncate_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!ftruncate_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/utimes.cpp b/interfaces/kits/js/src/mod_fs/properties/utimes.cpp index 53de8c7cd..de819baeb 100644 --- a/interfaces/kits/js/src/mod_fs/properties/utimes.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/utimes.cpp @@ -65,7 +65,7 @@ napi_value Utimes::Sync(napi_env env, napi_callback_info info) } std::unique_ptr utimes_req = { - new uv_fs_t, CommonFunc::fs_req_cleanup }; + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!utimes_req) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); -- Gitee From d2735cb46f4a9e83aa7d304a90ec9b973b80dae8 Mon Sep 17 00:00:00 2001 From: wuchengjun Date: Mon, 18 Aug 2025 13:14:04 +0000 Subject: [PATCH 15/21] update interfaces/kits/js/src/mod_fs/properties/read_text.cpp. Signed-off-by: wuchengjun --- interfaces/kits/js/src/mod_fs/properties/read_text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/read_text.cpp b/interfaces/kits/js/src/mod_fs/properties/read_text.cpp index bdbd14375..dcb46febf 100755 --- a/interfaces/kits/js/src/mod_fs/properties/read_text.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_text.cpp @@ -38,7 +38,7 @@ static tuple> GetReadTextArg(na bool succ = false; bool hasLen = false; unique_ptr encoding { new (std::nothrow) char[]{ "utf-8" } }; - if(!encoding){ + if (!encoding) { HILOGE("Failed to request heap memory."); return { false, offset, hasLen, len, nullptr }; } -- Gitee From 8ee433245506565f3f3607e44e4491157d739324 Mon Sep 17 00:00:00 2001 From: liyuke Date: Mon, 18 Aug 2025 10:00:13 +0800 Subject: [PATCH 16/21] =?UTF-8?q?read=5Fiterator=5Fani.cpp=20Wrap=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke Change-Id: Iae51688683278acbfed2900c2aece00af16d42bf --- .../ani/reader_iterator_ani.cpp | 2 +- .../ani/reader_iterator_result_ani.cpp | 16 ++++------------ .../ani/reader_iterator_result_ani.h | 2 +- .../class_tasksignal/fs_task_signal_test.cpp | 4 ++-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_ani.cpp b/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_ani.cpp index 8642ae512..d8dc3811f 100644 --- a/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_ani.cpp @@ -91,7 +91,7 @@ ani_object ReaderIteratorAni::Next(ani_env *env, [[maybe_unused]] ani_object obj } auto nextRet = ret.GetData().value(); - auto result = ReaderIteratorResultAni::Wrap(env, &nextRet); + auto result = ReaderIteratorResultAni::Wrap(env, nextRet); if (result == nullptr) { ErrorHandler::Throw(env, UNKNOWN_ERR); return nullptr; diff --git a/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.cpp b/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.cpp index b8efe806e..299832ea9 100644 --- a/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.cpp @@ -28,13 +28,8 @@ using namespace std; using namespace OHOS::FileManagement::ModuleFileIO; using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature; -ani_object ReaderIteratorResultAni::Wrap(ani_env *env, const ReaderIteratorResult *result) +ani_object ReaderIteratorResultAni::Wrap(ani_env *env, const ReaderIteratorResult &result) { - if (result == nullptr) { - HILOGE("ReaderIteratorResult pointer is null!"); - return nullptr; - } - auto classDesc = FS::ReaderIteratorResultInner::classDesc.c_str(); ani_class cls; if (ANI_OK != env->FindClass(classDesc, &cls)) { @@ -50,21 +45,18 @@ ani_object ReaderIteratorResultAni::Wrap(ani_env *env, const ReaderIteratorResul return nullptr; } - ani_long ptr = static_cast(reinterpret_cast(result)); ani_object obj; - if (ANI_OK != env->Object_New(cls, ctor, &obj, ptr)) { + if (ANI_OK != env->Object_New(cls, ctor, &obj)) { HILOGE("New %s obj Failed!", classDesc); return nullptr; } - const auto &done = result->done; - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "done", static_cast(done))) { + if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "done", static_cast(result.done))) { HILOGE("Set 'done' field value failed!"); return nullptr; } - const auto &value = result->value; - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "value", value)) { + if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "value", result.value)) { HILOGE("Set 'value' field value failed!"); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.h b/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.h index 31bf73e9c..81af29c16 100644 --- a/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.h +++ b/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.h @@ -27,7 +27,7 @@ namespace ANI { class ReaderIteratorResultAni final { public: - static ani_object Wrap(ani_env *env, const ReaderIteratorResult *result); + static ani_object Wrap(ani_env *env, const ReaderIteratorResult &result); }; } // namespace ANI } // namespace ModuleFileIO diff --git a/interfaces/test/unittest/js/mod_fs/class_tasksignal/fs_task_signal_test.cpp b/interfaces/test/unittest/js/mod_fs/class_tasksignal/fs_task_signal_test.cpp index 923204771..a75567d75 100644 --- a/interfaces/test/unittest/js/mod_fs/class_tasksignal/fs_task_signal_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/class_tasksignal/fs_task_signal_test.cpp @@ -136,7 +136,7 @@ HWTEST_F(FsTaskSignalTest, FsTaskSignalTest_Cancel_001, testing::ext::TestSize.L auto res = fsTaskSignal.Cancel(); - EXPECT_EQ(fsTaskSignal.taskSignal_, nullptr); + EXPECT_NE(fsTaskSignal.taskSignal_, nullptr); GTEST_LOG_(INFO) << "NClassTest-end FsTaskSignalTest_Cancel_001"; } @@ -175,7 +175,7 @@ HWTEST_F(FsTaskSignalTest, FsTaskSignalTest_OnCancel_001, testing::ext::TestSize auto res = fsTaskSignal.OnCancel(); - EXPECT_EQ(fsTaskSignal.taskSignal_, nullptr); + EXPECT_NE(fsTaskSignal.taskSignal_, nullptr); GTEST_LOG_(INFO) << "NClassTest-end FsTaskSignalTest_OnCancel_001"; } -- Gitee From 39d9fd3f43eb7636529cdb345a8b3200bdeb14a9 Mon Sep 17 00:00:00 2001 From: wuchengjun Date: Thu, 21 Aug 2025 02:58:17 +0000 Subject: [PATCH 17/21] update interfaces/kits/js/src/mod_fs/properties/movedir.cpp. Signed-off-by: wuchengjun --- interfaces/kits/js/src/mod_fs/properties/movedir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index f8b41ba9c..e68a9594d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -210,7 +210,7 @@ static int RecurMoveDir(const string &srcPath, const string &destPath, const int return ERRNO_NOERR; } - unique_ptr ptr = {new (std::nothrow) struct NameListArg, Deleter}; + unique_ptr ptr = { new (std::nothrow) struct NameListArg, Deleter }; if (!ptr) { HILOGE("Failed to request heap memory."); return ENOMEM; -- Gitee From 1e6454a1625e805358a31ce116d2a58478f15b27 Mon Sep 17 00:00:00 2001 From: wuchengjun Date: Thu, 21 Aug 2025 03:01:03 +0000 Subject: [PATCH 18/21] update interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp. Signed-off-by: wuchengjun --- interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index c7b6c9c60..cb0f8c52e 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -104,8 +104,8 @@ struct AccessArgs { static int UvAccess(const string &path, int mode) { - std::unique_ptr access_req = {new (std::nothrow) uv_fs_t, - CommonFunc::fs_req_cleanup}; + std::unique_ptr access_req = { + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup}; if (!access_req) { HILOGE("Failed to request heap memory."); return ENOMEM; -- Gitee From 36b2f9f3bf6e2332113fed852f7cab8f18288eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 22 Aug 2025 11:52:27 +0800 Subject: [PATCH 19/21] 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 | 36 +++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 0feb8411c..c31dfe740 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -53,6 +53,24 @@ static bool HasAccessIouringPermission() return true; } +static std::string GetAnonyString(const std::string &value) +{ + constexpr size_t INT32_PLAINTEXT_LENGTH = 4; + constexpr size_t INT32_MIN_ID_LENGTH = 8; + std::string res; + std::string tmpStr("******"); + size_t strLen = value.length(); + if (strLen < INT32_MIN_ID_LENGTH) { + return tmpStr; + } + + res.append(value, 0, INT32_PLAINTEXT_LENGTH); + res += tmpStr; + res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); + + return res; +} + static bool ValidateReqNum(uint32_t reqNum) { return reqNum > 0 && reqNum <= URING_QUEUE_SIZE; @@ -121,7 +139,7 @@ void HyperAio::HandleRequestError(std::vector &errorVec, int32_t error return; } for (auto &userdata : errorVec) { - HILOGE("HandleRequestError: userData = %{public}lu", userdata); + HILOGE("HandleRequestError: userData = %{private}lu", userdata); auto response = std::make_unique(userdata, errorcode, 0); ioResultCallBack_(std::move(response)); } @@ -189,10 +207,10 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) io_uring_sqe_set_data(sqe, reinterpret_cast(openInfo->userData)); io_uring_prep_openat(sqe, openInfo->dfd, static_cast(openInfo->path), openInfo->flags, openInfo->mode); - HILOGD("open flags = %{public}d, mode = %{public}u, userData = %{public}lu", + HILOGD("open flags = %{public}d, mode = %{public}u, userData = %{private}lu", openInfo->flags, openInfo->mode, openInfo->userData); HyperaioTrace trace("open flags:" + std::to_string(openInfo->flags) + "mode:" + std::to_string(openInfo->mode) - + "userData:" + std::to_string(openInfo->userData)); + + "userData:" + getAnonyString(std::to_string(openInfo->userData))); count++; openInfoVec.push_back(openInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { @@ -238,10 +256,10 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) struct ReadInfo *readInfo = &req->reqs[i]; io_uring_sqe_set_data(sqe, reinterpret_cast(readInfo->userData)); io_uring_prep_read(sqe, readInfo->fd, readInfo->buf, readInfo->len, readInfo->offset); - HILOGD("read len = %{public}u, offset = %{public}lu, userData = %{public}lu", + HILOGD("read len = %{public}u, offset = %{public}lu, userData = %{private}lu", readInfo->len, readInfo->offset, readInfo->userData); HyperaioTrace trace("read len:" + std::to_string(readInfo->len) + "offset:" + std::to_string(readInfo->offset) - + "userData:" + std::to_string(readInfo->userData)); + + "userData:" + getAnonyString(std::to_string(readInfo->userData))); count++; readInfoVec.push_back(readInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { @@ -287,10 +305,10 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) struct CancelInfo *cancelInfo = &req->reqs[i]; io_uring_sqe_set_data(sqe, reinterpret_cast(cancelInfo->userData)); io_uring_prep_cancel(sqe, reinterpret_cast(cancelInfo->targetUserData), 0); - HILOGD("cancel userData = %{public}lu, targetUserData = %{public}lu", + HILOGD("cancel userData = %{private}lu, targetUserData = %{private}lu", cancelInfo->userData, cancelInfo->targetUserData); - HyperaioTrace trace("cancel userData:" + std::to_string(cancelInfo->userData) - + "targetUserData:" + std::to_string(cancelInfo->targetUserData)); + HyperaioTrace trace("cancel userData:" + getAnonyString(std::to_string(cancelInfo->userData)) + + "targetUserData:" + getAnonyString(std::to_string(cancelInfo->targetUserData))); count++; cancelInfoVec.push_back(cancelInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { @@ -325,7 +343,7 @@ void HyperAio::HarvestRes() HILOGI("cqe failed, cqe->res = %{public}d", cqe->res); } auto response = std::make_unique(cqe->user_data, cqe->res, cqe->flags); - HyperaioTrace trace("harvest: userdata " + std::to_string(cqe->user_data) + HyperaioTrace trace("harvest: userdata " + getAnonyString(std::to_string(cqe->user_data)) + " res " + std::to_string(cqe->res) + "flags " + std::to_string(cqe->flags)); io_uring_cqe_seen(&pImpl_->uring_, cqe); if (ioResultCallBack_) { -- Gitee From 5dbaeb525311fcc49352bf286b459d308588de7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 22 Aug 2025 12:00:10 +0800 Subject: [PATCH 20/21] 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 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index c31dfe740..a3d98b93b 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -63,7 +63,7 @@ static std::string GetAnonyString(const std::string &value) if (strLen < INT32_MIN_ID_LENGTH) { return tmpStr; } - + res.append(value, 0, INT32_PLAINTEXT_LENGTH); res += tmpStr; res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); @@ -210,7 +210,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) HILOGD("open flags = %{public}d, mode = %{public}u, userData = %{private}lu", openInfo->flags, openInfo->mode, openInfo->userData); HyperaioTrace trace("open flags:" + std::to_string(openInfo->flags) + "mode:" + std::to_string(openInfo->mode) - + "userData:" + getAnonyString(std::to_string(openInfo->userData))); + + "userData:" + GetAnonyString(std::to_string(openInfo->userData))); count++; openInfoVec.push_back(openInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { @@ -259,7 +259,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) HILOGD("read len = %{public}u, offset = %{public}lu, userData = %{private}lu", readInfo->len, readInfo->offset, readInfo->userData); HyperaioTrace trace("read len:" + std::to_string(readInfo->len) + "offset:" + std::to_string(readInfo->offset) - + "userData:" + getAnonyString(std::to_string(readInfo->userData))); + + "userData:" + GetAnonyString(std::to_string(readInfo->userData))); count++; readInfoVec.push_back(readInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { @@ -307,8 +307,8 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) io_uring_prep_cancel(sqe, reinterpret_cast(cancelInfo->targetUserData), 0); HILOGD("cancel userData = %{private}lu, targetUserData = %{private}lu", cancelInfo->userData, cancelInfo->targetUserData); - HyperaioTrace trace("cancel userData:" + getAnonyString(std::to_string(cancelInfo->userData)) - + "targetUserData:" + getAnonyString(std::to_string(cancelInfo->targetUserData))); + HyperaioTrace trace("cancel userData:" + GetAnonyString(std::to_string(cancelInfo->userData)) + + "targetUserData:" + GetAnonyString(std::to_string(cancelInfo->targetUserData))); count++; cancelInfoVec.push_back(cancelInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { @@ -343,7 +343,7 @@ void HyperAio::HarvestRes() HILOGI("cqe failed, cqe->res = %{public}d", cqe->res); } auto response = std::make_unique(cqe->user_data, cqe->res, cqe->flags); - HyperaioTrace trace("harvest: userdata " + getAnonyString(std::to_string(cqe->user_data)) + HyperaioTrace trace("harvest: userdata " + GetAnonyString(std::to_string(cqe->user_data)) + " res " + std::to_string(cqe->res) + "flags " + std::to_string(cqe->flags)); io_uring_cqe_seen(&pImpl_->uring_, cqe); if (ioResultCallBack_) { -- Gitee From 8deff5f4be62124a7346f69fe76fc4bfa2c4e578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 22 Aug 2025 16:26:24 +0800 Subject: [PATCH 21/21] 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 | 28 ++++------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index a3d98b93b..112649c5f 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -53,24 +53,6 @@ static bool HasAccessIouringPermission() return true; } -static std::string GetAnonyString(const std::string &value) -{ - constexpr size_t INT32_PLAINTEXT_LENGTH = 4; - constexpr size_t INT32_MIN_ID_LENGTH = 8; - std::string res; - std::string tmpStr("******"); - size_t strLen = value.length(); - if (strLen < INT32_MIN_ID_LENGTH) { - return tmpStr; - } - - res.append(value, 0, INT32_PLAINTEXT_LENGTH); - res += tmpStr; - res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); - - return res; -} - static bool ValidateReqNum(uint32_t reqNum) { return reqNum > 0 && reqNum <= URING_QUEUE_SIZE; @@ -210,7 +192,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) HILOGD("open flags = %{public}d, mode = %{public}u, userData = %{private}lu", openInfo->flags, openInfo->mode, openInfo->userData); HyperaioTrace trace("open flags:" + std::to_string(openInfo->flags) + "mode:" + std::to_string(openInfo->mode) - + "userData:" + GetAnonyString(std::to_string(openInfo->userData))); + + "userData:" + std::to_string(openInfo->userData)); count++; openInfoVec.push_back(openInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { @@ -259,7 +241,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) HILOGD("read len = %{public}u, offset = %{public}lu, userData = %{private}lu", readInfo->len, readInfo->offset, readInfo->userData); HyperaioTrace trace("read len:" + std::to_string(readInfo->len) + "offset:" + std::to_string(readInfo->offset) - + "userData:" + GetAnonyString(std::to_string(readInfo->userData))); + + "userData:" + std::to_string(readInfo->userData)); count++; readInfoVec.push_back(readInfo->userData); if (count >= BATCH_SIZE || i == totalReqs - 1) { @@ -307,8 +289,8 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) io_uring_prep_cancel(sqe, reinterpret_cast(cancelInfo->targetUserData), 0); HILOGD("cancel userData = %{private}lu, targetUserData = %{private}lu", cancelInfo->userData, cancelInfo->targetUserData); - HyperaioTrace trace("cancel userData:" + GetAnonyString(std::to_string(cancelInfo->userData)) - + "targetUserData:" + GetAnonyString(std::to_string(cancelInfo->targetUserData))); + 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) { @@ -343,7 +325,7 @@ void HyperAio::HarvestRes() HILOGI("cqe failed, cqe->res = %{public}d", cqe->res); } auto response = std::make_unique(cqe->user_data, cqe->res, cqe->flags); - HyperaioTrace trace("harvest: userdata " + GetAnonyString(std::to_string(cqe->user_data)) + HyperaioTrace trace("harvest: userdata " + std::to_string(cqe->user_data) + " res " + std::to_string(cqe->res) + "flags " + std::to_string(cqe->flags)); io_uring_cqe_seen(&pImpl_->uring_, cqe); if (ioResultCallBack_) { -- Gitee