From dd8fabd0f237760c0ef581b7abf52099bf4b8426 Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Tue, 25 Mar 2025 17:19:39 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0platformsdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhongning5 --- interfaces/kits/rust/BUILD.gn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/rust/BUILD.gn b/interfaces/kits/rust/BUILD.gn index a4cc7d698..965a4ec21 100644 --- a/interfaces/kits/rust/BUILD.gn +++ b/interfaces/kits/rust/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -26,5 +26,6 @@ ohos_rust_shared_ffi("rust_file") { rustflags = [ "-Zstack-protector=all" ] deps = [ "//third_party/rust/crates/libc:lib" ] external_deps = [ "hilog:hilog_rust" ] + innerapi_tags = [ "platformsdk" ] public_configs = [ ":public_config" ] } -- Gitee From 4dcedb85c3ce94d6a1a068762e9a56e66efa2791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=E9=99=B6=E9=87=91=E6=B2=9B=E2=80=9D?= Date: Mon, 31 Mar 2025 21:04:54 +0800 Subject: [PATCH 02/17] =?UTF-8?q?tdd=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “陶金沛” --- .../test/unittest/class_file/rust_test.cpp | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/interfaces/test/unittest/class_file/rust_test.cpp b/interfaces/test/unittest/class_file/rust_test.cpp index 7b3800a8b..6c60bd3b1 100644 --- a/interfaces/test/unittest/class_file/rust_test.cpp +++ b/interfaces/test/unittest/class_file/rust_test.cpp @@ -95,10 +95,10 @@ HWTEST_F(RustTest, RustTest_ReaderIterator_0003, testing::ext::TestSize.Level1) * @tc.desc: Test function of NextLine() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNF */ -HWTEST_F(RustTest, RustTest_NextLine_0001, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_NextLine_0001, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_NextLine_0001"; @@ -119,10 +119,10 @@ HWTEST_F(RustTest, RustTest_NextLine_0001, testing::ext::TestSize.Level1) * @tc.desc: Test function of NextLine() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNF */ -HWTEST_F(RustTest, RustTest_NextLine_0002, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_NextLine_0002, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_NextLine_0002"; @@ -159,10 +159,10 @@ HWTEST_F(RustTest, RustTest_NextLine_0003, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0001, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0001, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0001"; @@ -182,10 +182,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0001, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0002, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0002, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0002"; @@ -208,10 +208,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0002, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0003, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0003, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0003"; @@ -254,10 +254,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0004, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0005, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0005, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0005"; @@ -280,10 +280,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0005, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0006, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0006, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0006"; @@ -303,10 +303,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0006, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0007, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0007, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0007"; @@ -322,10 +322,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0007, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0001, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0001, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0001"; @@ -347,10 +347,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0001, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0002, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0002, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0002"; @@ -372,10 +372,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0002, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0003, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0003, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0003"; @@ -393,10 +393,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0003, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0004, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0004, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0004"; @@ -412,10 +412,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0004, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0005, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0005, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0005"; @@ -432,10 +432,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0005, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0006, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0006, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0006"; @@ -452,10 +452,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0006, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0007, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0007, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0007"; @@ -472,10 +472,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0007, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0008, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0008, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0008"; @@ -492,10 +492,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0008, testing::ext::TestSize.Level1) * @tc.desc: Test function of GetParent() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNL */ -HWTEST_F(RustTest, RustTest_GetParent_0001, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_GetParent_0001, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_GetParent_0001"; -- Gitee From 1dd0d213f40b9082e741fee31e76ec9b22a5bfce Mon Sep 17 00:00:00 2001 From: repo sync -c Date: Thu, 10 Apr 2025 15:48:31 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E4=B8=AD=E9=80=94=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=A2=9E=E5=8A=A0scope=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 Change-Id: Iea71514be018757f3c0c6dfc1222bfbb3ac21553 --- utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp index 9cad32c85..ff421fc03 100644 --- a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp +++ b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp @@ -120,6 +120,7 @@ static void CallbackComplete(napi_env env, napi_status status, void *data) napi_value callback = ctx->cb_.Deref(env).val_; if (!bool(ctx->cb_)) { HILOGE("failed to get ref."); + napi_close_handle_scope(env, scope); return; } -- Gitee From 88e347e81679f6daee49d7e7f31a695a08cc8b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Thu, 10 Apr 2025 09:27:08 +0000 Subject: [PATCH 04/17] update utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp index ff421fc03..4f2e88a80 100644 --- a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp +++ b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 19f00b93a29d54f77ba9eecab58f2c1b17a69e45 Mon Sep 17 00:00:00 2001 From: y30045862 Date: Sat, 12 Apr 2025 23:52:41 +0800 Subject: [PATCH 05/17] fix randomaccess write async Signed-off-by: yangjingbo10 Change-Id: I8b01907ff6b349514d4cd01448b0d43711170448 --- .../randomaccessfile_n_exporter.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 3a620f1fc..bbe140fbb 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 @@ -275,8 +275,10 @@ napi_value RandomAccessFileNExporter::WriteSync(napi_env env, napi_callback_info struct AsyncIORafWriteArg { NRef rafRefWriteArrayBuf; + std::unique_ptr guardWriteStr_ = nullptr; int actLen = 0; explicit AsyncIORafWriteArg(NVal refWriteArrayBuf) : rafRefWriteArrayBuf(refWriteArrayBuf) {} + explicit AsyncIORafWriteArg(std::unique_ptr &&guardWriteStr) : guardWriteStr_(move(guardWriteStr)) {} ~AsyncIORafWriteArg() = default; }; @@ -286,7 +288,8 @@ static napi_value WriteExec(napi_env env, NFuncArg &funcArg, RandomAccessFileEnt void *buf = nullptr; size_t len = 0; int64_t offset = 0; - tie(succ, ignore, buf, len, offset) = + unique_ptr bufGuard = nullptr; + tie(succ, bufGuard, buf, len, offset) = CommonFunc::GetWriteArg(env, funcArg[NARG_POS::FIRST], funcArg[NARG_POS::SECOND]); if (!succ) { HILOGE("Invalid buffer/options"); @@ -294,7 +297,7 @@ static napi_value WriteExec(napi_env env, NFuncArg &funcArg, RandomAccessFileEnt return nullptr; } - auto arg = CreateSharedPtr(NVal(env, funcArg[NARG_POS::FIRST])); + auto arg = CreateSharedPtr(move(bufGuard)); if (arg == nullptr) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -319,9 +322,8 @@ static napi_value WriteExec(napi_env env, NFuncArg &funcArg, RandomAccessFileEnt auto cbCompl = [arg](napi_env env, NError err) -> NVal { if (err) { return { env, err.GetNapiErr(env) }; - } else { - return { NVal::CreateInt64(env, arg->actLen) }; } + return { NVal::CreateInt64(env, arg->actLen) }; }; NVal thisVar(env, funcArg.GetThisVar()); -- Gitee From 1123c589d22f465a484f1cf04e10f399711166f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=AD=90=E6=81=92?= Date: Mon, 14 Apr 2025 11:08:34 +0800 Subject: [PATCH 06/17] bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 魏子恒 --- bundle.json | 4 +++- file_api.gni | 4 ++++ interfaces/kits/js/BUILD.gn | 4 ++++ .../kits/js/src/mod_file/class_file/file_n_exporter.cpp | 4 ++++ interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h | 4 ++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 78b145b37..ded14f6a7 100644 --- a/bundle.json +++ b/bundle.json @@ -19,7 +19,9 @@ "SystemCapability.FileManagement.File.DistributedFile", "SystemCapability.FileManagement.File.Environment.FolderObtain" ], - "features": [], + "features": [ + "file_api_read_optimize" + ], "adapted_system_type": [ "mini","small","standard" ], "rom": "4096KB", "ram": "4096KB", diff --git a/file_api.gni b/file_api.gni index 7fc94ace6..16a290623 100644 --- a/file_api.gni +++ b/file_api.gni @@ -23,3 +23,7 @@ utils_path = "${file_api_path}/utils" use_mac = "${current_os}_${current_cpu}" == "mac_x64" || "${current_os}_${current_cpu}" == "mac_arm64" use_mingw_win = "${current_os}_${current_cpu}" == "mingw_x86_64" + +declare_args() { + file_api_read_optimize = false +} diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index e06a5cece..9fc445f9a 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -377,6 +377,10 @@ ohos_shared_library("file") { "hilog:libhilog", "napi:ace_napi", ] + + if (file_api_read_optimize) { + defines = [ "WEARABLE_PRODUCT" ] + } } ohos_shared_library("statfs") { diff --git a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp index 972c56b50..01f591e74 100644 --- a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp @@ -905,7 +905,11 @@ void ReadArrayBufferExec(napi_env env, void *data) if (read(fdg.GetFD(), buffer.get(), len) != FAILED) { asyncCallbackInfo->result = SUCCESS; asyncCallbackInfo->len = len; +#ifdef WEARABLE_PRODUCT + asyncCallbackInfo->contents = std::move(buffer); +#else asyncCallbackInfo->contents = std::string(buffer.get()); +#endif } } } else if (statPath == ENOENT) { diff --git a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h index b9760b8a5..f39a8069e 100644 --- a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h +++ b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h @@ -172,7 +172,11 @@ struct AsyncReadBufferCallbackInfo { int result = DEFAULT_RESULT; int errorType = -1; int32_t len = 0; +#ifdef WEARABLE_PRODUCT + std::unique_ptr contents = nullptr; +#else std::string contents = ""; +#endif }; class FileNExporter final : public NExporter { -- Gitee From 376b7f2111e682fd26766177d6e06656c79c1202 Mon Sep 17 00:00:00 2001 From: y30045862 Date: Thu, 24 Apr 2025 18:45:19 +0800 Subject: [PATCH 07/17] Fix ambiguous internal error Signed-off-by: yangjingbo10 Change-Id: I4fc65b4e830aeb39063ad09c3d63e48a3c25781c --- .../atomicfile_n_exporter.cpp | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_atomicfile/atomicfile_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_atomicfile/atomicfile_n_exporter.cpp index 456a2f8f0..6958df62b 100644 --- a/interfaces/kits/js/src/mod_fs/class_atomicfile/atomicfile_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_atomicfile/atomicfile_n_exporter.cpp @@ -73,7 +73,7 @@ static napi_value CreateStream(napi_env env, napi_callback_info info, const std: napi_status status = napi_load_module(env, moduleName, &streamrw); if (status != napi_ok) { HILOGE("Failed to load module"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to load module"); return nullptr; } @@ -81,7 +81,7 @@ static napi_value CreateStream(napi_env env, napi_callback_info info, const std: status = napi_get_named_property(env, streamrw, streamName.c_str(), &constructor); if (status != napi_ok) { HILOGE("Failed to get named property"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to get named property"); return nullptr; } @@ -92,7 +92,7 @@ static napi_value CreateStream(napi_env env, napi_callback_info info, const std: status = napi_new_instance(env, constructor, argc, argv, &streamObj); if (status != napi_ok) { HILOGE("Failed to create napi new instance"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to create napi new instance"); return nullptr; } @@ -135,7 +135,7 @@ static NVal InstantiateFile(napi_env env, int fd, std::string path, bool isUri) if (!objFile) { close(fd); HILOGE("Failed to instantiate class"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to instantiate class"); return NVal(); } @@ -143,7 +143,7 @@ static NVal InstantiateFile(napi_env env, int fd, std::string path, bool isUri) if (fileEntity == nullptr) { close(fd); HILOGE("Failed to get fileEntity"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to get fileEntity"); return NVal(); } auto fdg = CreateUniquePtr(fd, false); @@ -186,7 +186,7 @@ napi_value AtomicFileNExporter::GetBaseFile(napi_env env, napi_callback_info inf auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -195,7 +195,7 @@ napi_value AtomicFileNExporter::GetBaseFile(napi_env env, napi_callback_info inf if (rafEntity->baseFileName.size() >= PATH_MAX) { HILOGE("Base file name is too long"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Base file name is too long"); return nullptr; } @@ -221,7 +221,7 @@ napi_value AtomicFileNExporter::OpenRead(napi_env env, napi_callback_info info) auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -273,7 +273,7 @@ napi_value AtomicFileNExporter::ReadFully(napi_env env, napi_callback_info info) auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -299,7 +299,7 @@ napi_value AtomicFileNExporter::ReadFully(napi_env env, napi_callback_info info) auto [bufferData, readErrcode] = ReadFileToBuffer(env, file.get()); if (readErrcode != 0) { if (readErrcode == UNKROWN_ERR) { - NError(readErrcode).ThrowErr(env, "Internal error"); + NError(readErrcode).ThrowErr(env, "Failed to read file to buffer"); } else { NError(readErrcode).ThrowErr(env); } @@ -311,14 +311,14 @@ napi_value AtomicFileNExporter::ReadFully(napi_env env, napi_callback_info info) napi_status status = napi_create_external_arraybuffer( env, bufferData->buffer, bufferData->length, FinalizeCallback, bufferData.release(), &externalBuffer); if (status != napi_ok) { - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to create external arraybuffer"); return nullptr; } napi_value outputArray = nullptr; status = napi_create_typedarray(env, napi_int8_array, length, externalBuffer, 0, &outputArray); if (status != napi_ok) { - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to create typedarray"); return nullptr; } @@ -330,7 +330,7 @@ napi_value AtomicFileNExporter::StartWrite(napi_env env, napi_callback_info info auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -360,7 +360,7 @@ napi_value AtomicFileNExporter::StartWrite(napi_env env, napi_callback_info info napi_status status = napi_create_reference(env, writeStream, 1, &rafEntity->writeStreamObj); if (status != napi_ok) { HILOGE("Failed to create reference"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to create reference"); return nullptr; } return writeStream; @@ -371,7 +371,7 @@ napi_value AtomicFileNExporter::FinishWrite(napi_env env, napi_callback_info inf auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -382,7 +382,7 @@ napi_value AtomicFileNExporter::FinishWrite(napi_env env, napi_callback_info inf napi_status status = napi_get_reference_value(env, rafEntity->writeStreamObj, &writeStream); if (status != napi_ok) { HILOGE("Failed to get reference value"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to get reference value"); return nullptr; } @@ -394,7 +394,7 @@ napi_value AtomicFileNExporter::FinishWrite(napi_env env, napi_callback_info inf status = napi_delete_reference(env, rafEntity->writeStreamObj); if (status != napi_ok) { HILOGE("Failed to delete reference"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to delete reference"); return nullptr; } return nullptr; @@ -405,7 +405,7 @@ napi_value AtomicFileNExporter::FailWrite(napi_env env, napi_callback_info info) auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -416,7 +416,7 @@ napi_value AtomicFileNExporter::FailWrite(napi_env env, napi_callback_info info) napi_status status = napi_get_reference_value(env, rafEntity->writeStreamObj, &writeStream); if (status != napi_ok) { HILOGE("Failed to get reference value"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to get reference value"); return nullptr; } @@ -430,7 +430,7 @@ napi_value AtomicFileNExporter::FailWrite(napi_env env, napi_callback_info info) status = napi_delete_reference(env, rafEntity->writeStreamObj); if (status != napi_ok) { HILOGE("Failed to delete reference"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to delete reference"); } return nullptr; } @@ -440,7 +440,7 @@ napi_value AtomicFileNExporter::Delete(napi_env env, napi_callback_info info) auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } -- Gitee From 25863077af924a0966c8234bf490b7a5ec9e146d Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 27 Apr 2025 10:26:57 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMTP=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E8=BF=87=E7=A8=8B=E4=B8=AD=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E5=8A=9F=E8=83=BDbug=20Signed-off-by:=20reng?= =?UTF-8?q?uang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/kits/js/src/mod_fs/properties/copy.cpp | 13 +++++++++++++ interfaces/kits/js/src/mod_fs/properties/copy.h | 1 + interfaces/kits/native/task_signal/task_signal.cpp | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index ffd87bebc..2fb408fc6 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -97,6 +97,10 @@ static int OpenSrcFile(const string &srcPth, std::shared_ptr infos, i srcFd = open(srcPth.c_str(), O_RDONLY); if (srcFd < 0) { HILOGE("Error opening src file descriptor. errno = %{public}d", errno); + bool isCanceled = (infos->taskSignal != nullptr) && (infos->taskSignal->CheckCancelIfNeed(srcPth)); + if (isCanceled && Copy::IsMtpDeviceFilePath(srcPth)) { + return ECANCELED; + } return errno; } } @@ -850,6 +854,9 @@ tuple> Copy::CreateFileInfos( auto taskSignalEntity = NClass::GetEntityOf(infos->env, infos->copySignal.val_); if (taskSignalEntity != nullptr) { infos->taskSignal = taskSignalEntity->taskSignal_; + if (IsMtpDeviceFilePath(infos->srcPath)) { + infos->taskSignal->SetFileInfoOfRemoteTask("", infos->srcPath); + } } } return { ERRNO_NOERR, infos }; @@ -974,6 +981,12 @@ napi_value Copy::Async(napi_env env, napi_callback_info info) return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_COPY_NAME, cbExec, cbCompl).val_; } } + +bool Copy::IsMtpDeviceFilePath(const std::string &path) +{ + const std::string MTP_PATH_PREFIX = "/storage/External/mtp"; + return path.rfind(MTP_PATH_PREFIX, 0) != std::string::npos; +} } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.h b/interfaces/kits/js/src/mod_fs/properties/copy.h index b08fd68f6..1c2a2f913 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.h +++ b/interfaces/kits/js/src/mod_fs/properties/copy.h @@ -130,6 +130,7 @@ public: static std::map> jsCbMap_; static void UnregisterListener(std::shared_ptr fileInfos); static std::recursive_mutex mutex_; + static bool IsMtpDeviceFilePath(const std::string &path); private: // operator of napi diff --git a/interfaces/kits/native/task_signal/task_signal.cpp b/interfaces/kits/native/task_signal/task_signal.cpp index 4700448d2..c87de7055 100644 --- a/interfaces/kits/native/task_signal/task_signal.cpp +++ b/interfaces/kits/native/task_signal/task_signal.cpp @@ -17,12 +17,16 @@ #include "distributed_file_daemon_manager.h" #include "filemgmt_libhilog.h" +#include namespace OHOS { namespace DistributedFS { namespace ModuleTaskSignal { using namespace FileManagement; constexpr int CANCEL_ERR = -3; +const char CANCEL_XATTR_KEY[] = {"user.cancelcopy"}; +const std::string MTP_PATH_PREFIX = "/storage/External/mtp"; + int32_t TaskSignal::Cancel() { HILOGD("TaskSignal Cancel in."); @@ -40,6 +44,13 @@ int32_t TaskSignal::Cancel() } OnCancel(); return ret; + } else { + if (filePath_.rfind(MTP_PATH_PREFIX, 0) != std::string::npos) { + std::string value; + if (setxattr(filePath_.c_str(), CANCEL_XATTR_KEY, value.c_str(), value.size(), 0) < 0) { + HILOGE("cancelcopy setxattr fail, errno is %{public}d", errno); + } + } } needCancel_.store(true); return 0; -- Gitee From 385bcfa8a5be10a81f8b147a0f59dee2a8da8589 Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 27 Apr 2025 03:18:13 +0000 Subject: [PATCH 09/17] update interfaces/kits/js/src/mod_fs/properties/copy.cpp. Signed-off-by: renguang1116 --- interfaces/kits/js/src/mod_fs/properties/copy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 2fb408fc6..ba09491ce 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -53,6 +53,7 @@ const std::string NETWORK_PARA = "?networkid="; const string PROCEDURE_COPY_NAME = "FileFSCopy"; const std::string MEDIALIBRARY_DATA_URI = "datashare:///media"; const std::string MEDIA = "media"; +const std::string MTP_PATH_PREFIX = "/storage/External/mtp"; const int SLEEP_TIME = 100000; constexpr int DISMATCH = 0; constexpr int MATCH = 1; @@ -984,7 +985,6 @@ napi_value Copy::Async(napi_env env, napi_callback_info info) bool Copy::IsMtpDeviceFilePath(const std::string &path) { - const std::string MTP_PATH_PREFIX = "/storage/External/mtp"; return path.rfind(MTP_PATH_PREFIX, 0) != std::string::npos; } } // namespace ModuleFileIO -- Gitee From c9a381cefd4f2205548a7ad36b240901bc8b25af Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 27 Apr 2025 12:36:01 +0000 Subject: [PATCH 10/17] update interfaces/kits/native/task_signal/task_signal.cpp. Signed-off-by: renguang1116 --- interfaces/kits/native/task_signal/task_signal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/native/task_signal/task_signal.cpp b/interfaces/kits/native/task_signal/task_signal.cpp index c87de7055..e8c72d3bb 100644 --- a/interfaces/kits/native/task_signal/task_signal.cpp +++ b/interfaces/kits/native/task_signal/task_signal.cpp @@ -46,7 +46,7 @@ int32_t TaskSignal::Cancel() return ret; } else { if (filePath_.rfind(MTP_PATH_PREFIX, 0) != std::string::npos) { - std::string value; + std::string value = ""; if (setxattr(filePath_.c_str(), CANCEL_XATTR_KEY, value.c_str(), value.size(), 0) < 0) { HILOGE("cancelcopy setxattr fail, errno is %{public}d", errno); } -- Gitee From cf81fd95524d6c6852740e2d8484097159b2fd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 21:45:10 +0800 Subject: [PATCH 11/17] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 94 +++++++++ interfaces/kits/hyperaio/include/libhilog.h | 56 +++++ interfaces/kits/hyperaio/src/hyperaio.cpp | 218 ++++++++++++++++++++ 3 files changed, 368 insertions(+) create mode 100644 interfaces/kits/hyperaio/include/hyperaio.h create mode 100644 interfaces/kits/hyperaio/include/libhilog.h create mode 100644 interfaces/kits/hyperaio/src/hyperaio.cpp diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h new file mode 100644 index 000000000..6ece2728b --- /dev/null +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILEMANAGEMENT_FILE_API_INTERFACES_KITS_IOURING_HYPER_AIO_H +#define FILEMANAGEMENT_FILE_API_INTERFACES_KITS_IOURING_HYPER_AIO_H + +#include +#include +#include "liburing.h" + +namespace OHOS { +namespace HyperAio { +#define IOURING_APP_PREMISSION (1U << 0) + +struct ReadInfo { + int32_t fd; + uint32_t len; + uint64_t offset; + void *buf; + uint64_t userData; +}; + +struct ReadReqs { + uint32_t reqNum; + struct ReadInfo *reqs; +}; + +struct OpenInfo { + int32_t dfd; + int32_t flags; + mode_t mode; + void *path; + uint64_t userData; +}; + +struct OpenReqs { + uint32_t reqNum; + struct OpenInfo *reqs; +}; + +struct CancelInfo { + uint64_t userData; + uint64_t targetUserData; +}; + +struct CancelReqs { + uint32_t reqNum; + struct CancelInfo *reqs; +}; + +struct IoResponse { + uint64_t userData; + int32_t res; + uint32_t flags; + IoResponse(uint64_t userData, int32_t res, uint32_t flags) + : userData(userData), + res(res), + flags(flags) { + } +}; + +class HyperAio { +public: + using ProcessIoResultCallBack = std::function)>; + uint32_t SupportIouring(); + int32_t CtxInit(ProcessIoResultCallBack *callBack); + int32_t StartReadReqs(ReadReqs *req); + int32_t StartOpenReqs(OpenReqs *req); + int32_t StartCancelReqs(CancelReqs *req); + int32_t DestroyCtx(); +private: + io_uring uring_; + ProcessIoResultCallBack ioResultCallBack_ = nullptr; + std::thread harvestThread_; + std::atomic stopThread_; + std::atomic initialized_; + void HarvestRes(); + struct io_uring_sqe* GetSqeWithRetry(struct io_uring *ring); +}; +} +} +#endif \ No newline at end of file diff --git a/interfaces/kits/hyperaio/include/libhilog.h b/interfaces/kits/hyperaio/include/libhilog.h new file mode 100644 index 000000000..9e882f46b --- /dev/null +++ b/interfaces/kits/hyperaio/include/libhilog.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILEMGMT_LIBHILOG_H +#define FILEMGMT_LIBHILOG_H + +#include "hilog/log.h" + +#include + +namespace OHOS { +#ifndef LOG_DOMAIN +#define LOG_DOMAIN 0xD001600 +#endif + +#ifndef LOG_TAG +#define LOG_TAG "FileManagement" +#endif + +#if defined __FILE_NAME__ +#define FILEMGMT_FILE_NAME __FILE_NAME__ +#else +#include +#define FILEMGMT_FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#endif + +#define HILOGF(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +#define HILOGE(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +#define HILOGW(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +#define HILOGI(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +#define HILOGD(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +} // namespace OHOS + +#endif // FILEMGMT_LIBHILOG_H \ No newline at end of file diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp new file mode 100644 index 000000000..400ba2865 --- /dev/null +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hyperaio.h" +#include "libhilog.h" +#include +#include +#include "ipc_skeleton.h" +#include "accesstoken_kit.h" + +namespace OHOS { +namespace HyperAio { +const uint32_t URING_QUEUE_SIZE = 512; +const uint32_t DELAY = 20; +const uint32_t BATCH_SIZE = 128; +const uint32_t RETRIES = 3; + +static bool HasAccessIouringPermission() +{ + Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); + const std::string permissionName = "ohos.permission.ALLOW_IOURING"; + int32_t res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, permissionName); + if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + HILOG("have no ALLOW_IOURING permission, AccessTokenID = %{public}u", tokenCaller); + return false; + } + return true; +} + +uint32_t HyperAio::SupportIouring() +{ + uint32_t flags = 0; + if (HasAccessIouringPermission()) { + flags |= IOURING_APP_PERMISSION; + } + return flags; +} + +int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) +{ + int32_t ret = io_uring_queue_init(URING_QUEUE_SIZE, &uring_, 0); + if (ret < 0) { + HILOGE("init io_uring failed, ret = %{public}d", ret); + return ret; + } + ioResultCallBack_ = *callBack; + stopThread_.store(false); + harvestThread_ = std::thread(&HyperAio::HarvestRes, this); + initialized_.sotre(true); + return EOK; +} + +struct io_uring_sqe* HyperAio::GetSqeWithRetry(struct io_uring *ring) +{ + struct io_uring_sqe *sqe; + for (uint32_t i = 0; i < RETRIES; i++) { + sqe = io_uring_get_sqe(ring); + if (sqe != nullptr) { + return sqe; + } + io_uring_submit(ring); + std::this_thread::sleep_for(std::chrono::milliseconds(DELAY)); + } + return nullptr; +} + +int32_t HyperAio::StartOpenReqs(OpenReqs *req) +{ + if (req == nullptr || req->reqs == nullptr) { + return EINVAL; + } + if (!initialized_.load()) { + HILOGE("HyperAio is not initialized"); + return EPERM; + } + uint32_t totalReqs = req->reqNum; + for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { + uint32_t end = std::min(totalReqs, start + BATCH_SIZE); + if (end < start) { + HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + return EINVAL; + } + for (uint32_t i = start; i < end; ++i) { + struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + if (sqe == nullptr) { + HILOGE("get sqe failed"); + return ENOMEM; + } + struct OpenInfo *openInfo = &req->reqs[i]; + 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); + } + int32_t ret = io_uring_submit(&uring_); + if (ret < 0) { + HILOGE("submit open reqs failed, ret = %{public}d", ret); + return ret; + } + } + return EOK; +} + +int32_t HyperAio::StartReadReqs(ReadReqs *req) +{ + if (req == nullptr || req->reqs == nullptr) { + return EINVAL; + } + if (!initialized_.load()) { + HILOGE("HyperAio is not initialized"); + return EPERM; + } + uint32_t totalReqs = req->reqNum; + for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { + uint32_t end = std::min(totalReqs, start + BATCH_SIZE); + if (end < start) { + HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + return EINVAL; + } + for (uint32_t i = start; i < end; ++i) { + struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + if (sqe == nullptr) { + HILOGE("get sqe failed"); + return ENOMEM; + } + 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); + } + int32_t ret = io_uring_submit(&uring_); + if (ret < 0) { + HILOGE("submit read reqs failed, ret = %{public}d", ret); + return ret; + } + } + return EOK; +} + +int32_t HyperAio::StartCancelReqs(CancelReqs *req) +{ + if (req == nullptr || req->reqs == nullptr) { + return EINVAL; + } + if (!initialized_.load()) { + HILOGE("HyperAio is not initialized"); + return EPERM; + } + uint32_t totalReqs = req->reqNum; + for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { + uint32_t end = std::min(totalReqs, start + BATCH_SIZE); + if (end < start) { + HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + return EINVAL; + } + for (uint32_t i = start; i < end; ++i) { + struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + if (sqe == nullptr) { + HILOGE("get sqe failed"); + return ENOMEM; + } + 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); + } + int32_t ret = io_uring_submit(&uring_); + if (ret < 0) { + HILOGE("submit open reqs failed, ret = %{public}d", ret); + return ret; + } + } + return EOK; +} + +void HyperAio::HarvestRes() +{ + struct __kernel_timespec timeout = { .tv_sec = 0, .tv_nsec = 200 * 1e6 }; + while (!stopThread_.load()) { + struct io_uring_cqe *cqe; + int32_t ret = io_uring_wait_cqe_timeout(&uring_, &cqe, %timeout); + if (ret == -ETIME) { + continue; + } + if (ret < 0 || cqe == nullptr) { + HILOGI("wait cqe failed, ret = %{public}d", ret); + continue; + } + auto response = std::make_unique(cqe->user_data, cqe->res, cqe->flags); + io_uring_cqe_seen(&uring_, cqe); + if (ioResultCallBack_) { + ioResultCallBack_(std::move(response)); + } + } +} + +int32_t HyperAio::DestroyCtx() +{ + stopThread_.store(true); + if (harvestThread_.joinable()) { + harvestThread_.join(); + } + io_uring_queue_exit(&uring_); + initialized_store(false); + return EOK; +} +} +} \ No newline at end of file -- Gitee From 826e21cdffe420b45cfd9190c2ff909628e61d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 22:58:02 +0800 Subject: [PATCH 12/17] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../test/unittest/hyperaio/hyperaio_test.cpp | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 interfaces/test/unittest/hyperaio/hyperaio_test.cpp diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp new file mode 100644 index 000000000..ce5b9f514 --- /dev/null +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "hyperaio.h" + +namespace { + using namespace std; + using namespace OHOS::HyperAio; + + class HyperAioTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + }; + + /** + * @tc.name: HyperAio_StartOpenReqs_0000 + * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + OpenInfo openInfo = {0, O_RDWR, 0, nullptr, 12345}; + OpenReqs openReqs = {1, &openInfo}; + result = hyperAio->StartOpenReqs(&openReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartReadReqs_0000 + * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + ReadInfo readInfo = {0, 1024, 0, nullptr, 12345}; + ReadReqs readReqs = {1, &readInfo}; + result = hyperAio->StartReadReqs(&readReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartCancelReqs_0000 + * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + CancelInfo cancelInfo = {0, 1024, 0, nullptr, 12345}; + CancelReqs cancelReqs = {1, &cancelInfo}; + result = hyperAio->StartCancelReqs(&cancelReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0000"; + } + +} -- Gitee From 54607f6ff2fc5d2c8b280e381abf045d7ab7b4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 22:59:15 +0800 Subject: [PATCH 13/17] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../test/unittest/hyperaio/hyperaio_test.cpp | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 interfaces/test/unittest/hyperaio/hyperaio_test.cpp diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp deleted file mode 100644 index ce5b9f514..000000000 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "hyperaio.h" - -namespace { - using namespace std; - using namespace OHOS::HyperAio; - - class HyperAioTest : public testing::Test { - public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; - }; - - /** - * @tc.name: HyperAio_StartOpenReqs_0000 - * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0000, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0000"; - std::unique_ptr hyperAio = std::make_unique(); - int32_t result = hyperAio->CtxInit(nullptr); - EXPECT_EQ(result, EOK); - OpenInfo openInfo = {0, O_RDWR, 0, nullptr, 12345}; - OpenReqs openReqs = {1, &openInfo}; - result = hyperAio->StartOpenReqs(&openReqs); - EXPECT_EQ(result, EOK); - GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; - } - - /** - * @tc.name: HyperAio_StartReadReqs_0000 - * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; - std::unique_ptr hyperAio = std::make_unique(); - int32_t result = hyperAio->CtxInit(nullptr); - EXPECT_EQ(result, EOK); - ReadInfo readInfo = {0, 1024, 0, nullptr, 12345}; - ReadReqs readReqs = {1, &readInfo}; - result = hyperAio->StartReadReqs(&readReqs); - EXPECT_EQ(result, EOK); - GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; - } - - /** - * @tc.name: HyperAio_StartCancelReqs_0000 - * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0000, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0000"; - std::unique_ptr hyperAio = std::make_unique(); - int32_t result = hyperAio->CtxInit(nullptr); - EXPECT_EQ(result, EOK); - CancelInfo cancelInfo = {0, 1024, 0, nullptr, 12345}; - CancelReqs cancelReqs = {1, &cancelInfo}; - result = hyperAio->StartCancelReqs(&cancelReqs); - EXPECT_EQ(result, EOK); - GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0000"; - } - -} -- Gitee From a2077d87a598f49313944af0c3963d126cd4c64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 23:00:18 +0800 Subject: [PATCH 14/17] hyperaio 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 400ba2865..5932c113f 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -176,7 +176,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) } int32_t ret = io_uring_submit(&uring_); if (ret < 0) { - HILOGE("submit open reqs failed, ret = %{public}d", ret); + HILOGE("submit cancel reqs failed, ret = %{public}d", ret); return ret; } } -- Gitee From 879e81d5cd92bde17b87d2e7a1be970b2e580c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 23:01:40 +0800 Subject: [PATCH 15/17] hyperaio 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 5932c113f..3e486284c 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -188,7 +188,7 @@ void HyperAio::HarvestRes() struct __kernel_timespec timeout = { .tv_sec = 0, .tv_nsec = 200 * 1e6 }; while (!stopThread_.load()) { struct io_uring_cqe *cqe; - int32_t ret = io_uring_wait_cqe_timeout(&uring_, &cqe, %timeout); + int32_t ret = io_uring_wait_cqe_timeout(&uring_, &cqe, &timeout); if (ret == -ETIME) { continue; } -- Gitee From 4ef5883cd9de0188b0daed86c0c8033857eaf724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 23:07:04 +0800 Subject: [PATCH 16/17] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 3e486284c..f0fec25df 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -33,7 +33,7 @@ static bool HasAccessIouringPermission() const std::string permissionName = "ohos.permission.ALLOW_IOURING"; int32_t res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, permissionName); if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { - HILOG("have no ALLOW_IOURING permission, AccessTokenID = %{public}u", tokenCaller); + HILOGE("have no ALLOW_IOURING permission, AccessTokenID = %{public}u", tokenCaller); return false; } return true; @@ -58,7 +58,7 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) ioResultCallBack_ = *callBack; stopThread_.store(false); harvestThread_ = std::thread(&HyperAio::HarvestRes, this); - initialized_.sotre(true); + initialized_.store(true); return EOK; } @@ -89,7 +89,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { uint32_t end = std::min(totalReqs, start + BATCH_SIZE); if (end < start) { - HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + HILOGE("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); return EINVAL; } for (uint32_t i = start; i < end; ++i) { @@ -125,7 +125,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { uint32_t end = std::min(totalReqs, start + BATCH_SIZE); if (end < start) { - HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + HILOGE("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); return EINVAL; } for (uint32_t i = start; i < end; ++i) { @@ -136,8 +136,7 @@ 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); + io_uring_prep_read(sqe, readInfo->fd, readInfo->buf, readInfo->len, readInfo->offset); } int32_t ret = io_uring_submit(&uring_); if (ret < 0) { @@ -161,7 +160,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { uint32_t end = std::min(totalReqs, start + BATCH_SIZE); if (end < start) { - HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + HILOGE("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); return EINVAL; } for (uint32_t i = start; i < end; ++i) { @@ -211,7 +210,7 @@ int32_t HyperAio::DestroyCtx() harvestThread_.join(); } io_uring_queue_exit(&uring_); - initialized_store(false); + initialized_.store(false); return EOK; } } -- Gitee From 35e0c099e5ee3b36b183741abdf09c965fb6f236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 9 May 2025 09:13:34 +0800 Subject: [PATCH 17/17] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index f0fec25df..f719cf729 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -50,6 +50,10 @@ uint32_t HyperAio::SupportIouring() int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) { + if (callBack == nullptr) { + HILOGE("callBack is null"); + return -EINVAL; + } int32_t ret = io_uring_queue_init(URING_QUEUE_SIZE, &uring_, 0); if (ret < 0) { HILOGE("init io_uring failed, ret = %{public}d", ret); -- Gitee