From b7cbcf48d998ddb19aa16bce1af65d29caccb744 Mon Sep 17 00:00:00 2001 From: lianwei Date: Thu, 24 Oct 2024 19:30:49 +0800 Subject: [PATCH] =?UTF-8?q?storage=5Fservice=E6=8E=A5=E5=85=A5xcollie?= =?UTF-8?q?=E6=94=AF=E6=8C=81watchdog=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianwei --- bundle.json | 1 + services/storage_daemon/BUILD.gn | 3 ++ .../include/utils/storage_xcollie.h | 30 +++++++++++++++++++ .../ipc/src/storage_daemon_stub.cpp | 28 +++++++++++++++-- services/storage_daemon/ipc/test/BUILD.gn | 2 ++ .../storage_daemon/utils/storage_xcollie.cpp | 30 +++++++++++++++++++ test/fuzztest/storagedaemon_fuzzer/BUILD.gn | 2 ++ .../BUILD.gn | 2 ++ .../BUILD.gn | 2 ++ 9 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 services/storage_daemon/include/utils/storage_xcollie.h create mode 100644 services/storage_daemon/utils/storage_xcollie.cpp diff --git a/bundle.json b/bundle.json index f8c0b985..9f000bb1 100644 --- a/bundle.json +++ b/bundle.json @@ -47,6 +47,7 @@ "FreeBSD", "file_api", "gptfdisk", + "hicollie", "hilog", "hisysevent", "hitrace", diff --git a/services/storage_daemon/BUILD.gn b/services/storage_daemon/BUILD.gn index ae3d2bad..1ce3e45a 100644 --- a/services/storage_daemon/BUILD.gn +++ b/services/storage_daemon/BUILD.gn @@ -121,6 +121,7 @@ ohos_executable("storage_daemon") { "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", + "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", @@ -280,12 +281,14 @@ ohos_shared_library("storage_common_utils") { "./utils/mount_argument_utils.cpp", "./utils/set_flag_utils.cpp", "./utils/storage_radar.cpp", + "./utils/storage_xcollie.cpp", "./utils/string_utils.cpp", "./utils/zip_util.cpp", ] external_deps = [ "c_utils:utils", + "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", "zlib:shared_libz", diff --git a/services/storage_daemon/include/utils/storage_xcollie.h b/services/storage_daemon/include/utils/storage_xcollie.h new file mode 100644 index 00000000..dde185dd --- /dev/null +++ b/services/storage_daemon/include/utils/storage_xcollie.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 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 FILEMANAGEMENT_STORAGE_XCOLLIE_H +#define FILEMANAGEMENT_STORAGE_XCOLLIE_H + +#include "xcollie/xcollie.h" +#include + +namespace OHOS { +namespace StorageDaemon { +class StorageXCollie { +public: + static int SetTimer(const std::string &name, uint32_t timeout); + static void CancelTimer(int timerId); +}; +} +} +#endif //FILEMANAGEMENT_STORAGE_XCOLLIE_H diff --git a/services/storage_daemon/ipc/src/storage_daemon_stub.cpp b/services/storage_daemon/ipc/src/storage_daemon_stub.cpp index 82ebd687..765cc4e8 100644 --- a/services/storage_daemon/ipc/src/storage_daemon_stub.cpp +++ b/services/storage_daemon/ipc/src/storage_daemon_stub.cpp @@ -19,10 +19,12 @@ #include "storage_service_errno.h" #include "storage_service_log.h" #include "string_ex.h" +#include "utils/storage_xcollie.h" namespace OHOS { namespace StorageDaemon { using namespace std; +const unsigned int LOCAL_TIME_OUT_SECONDS = 10; StorageDaemonStub::StorageDaemonStub() { @@ -425,8 +427,9 @@ int32_t StorageDaemonStub::HandleGenerateUserKeys(MessageParcel &data, MessagePa { uint32_t userId = data.ReadUint32(); uint32_t flags = data.ReadUint32(); - + int timerId = StorageXCollie::SetTimer("storage:GenerateUserKeys", LOCAL_TIME_OUT_SECONDS); int err = GenerateUserKeys(userId, flags); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -437,8 +440,9 @@ int32_t StorageDaemonStub::HandleGenerateUserKeys(MessageParcel &data, MessagePa int32_t StorageDaemonStub::HandleDeleteUserKeys(MessageParcel &data, MessageParcel &reply) { uint32_t userId = data.ReadUint32(); - + int timerId = StorageXCollie::SetTimer("storage:DeleteUserKeys", LOCAL_TIME_OUT_SECONDS); int err = DeleteUserKeys(userId); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -458,7 +462,9 @@ int32_t StorageDaemonStub::HandleUpdateUserAuth(MessageParcel &data, MessageParc data.ReadUInt8Vector(&oldSecret); data.ReadUInt8Vector(&newSecret); + int timerId = StorageXCollie::SetTimer("storage:UpdateUserAuth", LOCAL_TIME_OUT_SECONDS); int err = UpdateUserAuth(userId, secureUid, token, oldSecret, newSecret); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -500,7 +506,9 @@ int32_t StorageDaemonStub::HandleActiveUserKey(MessageParcel &data, MessageParce data.ReadUInt8Vector(&token); data.ReadUInt8Vector(&secret); + int timerId = StorageXCollie::SetTimer("storage:ActiveUserKey", LOCAL_TIME_OUT_SECONDS); int err = ActiveUserKey(userId, token, secret); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -512,7 +520,9 @@ int32_t StorageDaemonStub::HandleInactiveUserKey(MessageParcel &data, MessagePar { uint32_t userId = data.ReadUint32(); + int timerId = StorageXCollie::SetTimer("storage:InactiveUserKey", LOCAL_TIME_OUT_SECONDS); int err = InactiveUserKey(userId); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -524,7 +534,9 @@ int32_t StorageDaemonStub::HandleLockUserScreen(MessageParcel &data, MessageParc { uint32_t userId = data.ReadUint32(); + int timerId = StorageXCollie::SetTimer("storage:LockUserScreen", LOCAL_TIME_OUT_SECONDS); int err = LockUserScreen(userId); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -541,7 +553,9 @@ int32_t StorageDaemonStub::HandleUnlockUserScreen(MessageParcel &data, MessagePa data.ReadUInt8Vector(&token); data.ReadUInt8Vector(&secret); + int timerId = StorageXCollie::SetTimer("storage:UnlockUserScreen", LOCAL_TIME_OUT_SECONDS); int err = UnlockUserScreen(userId, token, secret); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -553,7 +567,9 @@ int32_t StorageDaemonStub::HandleGetLockScreenStatus(MessageParcel &data, Messag { uint32_t userId = data.ReadUint32(); bool lockScreenStatus = false; + int timerId = StorageXCollie::SetTimer("storage:GetLockScreenStatus", LOCAL_TIME_OUT_SECONDS); int err = GetLockScreenStatus(userId, lockScreenStatus); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteBool(lockScreenStatus)) { return E_WRITE_REPLY_ERR; } @@ -569,7 +585,9 @@ int32_t StorageDaemonStub::HandleGenerateAppkey(MessageParcel &data, MessageParc uint32_t userId = data.ReadUint32(); uint32_t hashId = data.ReadUint32(); std::string keyId; + int timerId = StorageXCollie::SetTimer("storage:GenerateAppkey", LOCAL_TIME_OUT_SECONDS); int err = GenerateAppkey(userId, hashId, keyId); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteString(keyId)) { return E_WRITE_REPLY_ERR; } @@ -584,7 +602,9 @@ int32_t StorageDaemonStub::HandleDeleteAppkey(MessageParcel &data, MessageParcel { uint32_t userId = data.ReadUint32(); std::string keyId = data.ReadString(); + int timerId = StorageXCollie::SetTimer("storage:DeleteAppkey", LOCAL_TIME_OUT_SECONDS); int err = DeleteAppkey(userId, keyId); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -624,7 +644,9 @@ int32_t StorageDaemonStub::HandleSetRecoverKey(MessageParcel &data, MessageParce int32_t StorageDaemonStub::HandleUpdateKeyContext(MessageParcel &data, MessageParcel &reply) { uint32_t userId = data.ReadUint32(); + int timerId = StorageXCollie::SetTimer("storage:UpdateKeyContext", LOCAL_TIME_OUT_SECONDS); int err = UpdateKeyContext(userId); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } @@ -778,7 +800,9 @@ int32_t StorageDaemonStub::HandleGetFileEncryptStatus(MessageParcel &data, Messa uint32_t userId = data.ReadUint32(); bool needCheckDirMount = data.ReadBool(); bool isEncrypted = true; + int timerId = StorageXCollie::SetTimer("storage:GetFileEncryptStatus", LOCAL_TIME_OUT_SECONDS); int err = GetFileEncryptStatus(userId, isEncrypted, needCheckDirMount); + StorageXCollie::CancelTimer(timerId); if (!reply.WriteInt32(err)) { return E_WRITE_REPLY_ERR; } diff --git a/services/storage_daemon/ipc/test/BUILD.gn b/services/storage_daemon/ipc/test/BUILD.gn index 93dc43ca..5c6cc843 100644 --- a/services/storage_daemon/ipc/test/BUILD.gn +++ b/services/storage_daemon/ipc/test/BUILD.gn @@ -88,6 +88,7 @@ ohos_unittest("storage_daemon_test") { "c_utils:utils", "dfs_service:cloud_daemon_kit_inner", "eventhandler:libeventhandler", + "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", "huks:libhukssdk", @@ -192,6 +193,7 @@ ohos_unittest("storage_daemon_stub_test") { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", + "hicollie:libhicollie", "hilog:libhilog", "huks:libhukssdk", "init:libbegetutil", diff --git a/services/storage_daemon/utils/storage_xcollie.cpp b/services/storage_daemon/utils/storage_xcollie.cpp new file mode 100644 index 00000000..b875ca76 --- /dev/null +++ b/services/storage_daemon/utils/storage_xcollie.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 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. + */ + +#include "utils/storage_xcollie.h" + +namespace OHOS { +namespace StorageDaemon { +int StorageXCollie::SetTimer(const std::string &name, uint32_t timeout) +{ + return HiviewDFX::XCollie::GetInstance().SetTimer(name, timeout, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG); +} + +void StorageXCollie::CancelTimer(int timerId) +{ + HiviewDFX::XCollie::GetInstance().CancelTimer(timerId); +} +} +} // namespace OHOS::StorageDaemon diff --git a/test/fuzztest/storagedaemon_fuzzer/BUILD.gn b/test/fuzztest/storagedaemon_fuzzer/BUILD.gn index a3afead4..f13a1e8b 100644 --- a/test/fuzztest/storagedaemon_fuzzer/BUILD.gn +++ b/test/fuzztest/storagedaemon_fuzzer/BUILD.gn @@ -46,6 +46,7 @@ ohos_fuzztest("StorageDaemonFuzzTest") { "${storage_daemon_path}/utils/mount_argument_utils.cpp", "${storage_daemon_path}/utils/set_flag_utils.cpp", "${storage_daemon_path}/utils/storage_radar.cpp", + "${storage_daemon_path}/utils/storage_xcollie.cpp", "${storage_daemon_path}/utils/string_utils.cpp", "${storage_daemon_path}/utils/zip_util.cpp", "${storage_service_path}/test/fuzztest/storagedaemon_fuzzer/storagedaemon_fuzzer.cpp", @@ -72,6 +73,7 @@ ohos_fuzztest("StorageDaemonFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", + "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", "huks:libhukssdk", diff --git a/test/fuzztest/storagedaemoncreatesharefile_fuzzer/BUILD.gn b/test/fuzztest/storagedaemoncreatesharefile_fuzzer/BUILD.gn index c7827f82..923a5697 100644 --- a/test/fuzztest/storagedaemoncreatesharefile_fuzzer/BUILD.gn +++ b/test/fuzztest/storagedaemoncreatesharefile_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("StorageDaemonCreateShareFileFuzzTest") { "${storage_daemon_path}/utils/mount_argument_utils.cpp", "${storage_daemon_path}/utils/set_flag_utils.cpp", "${storage_daemon_path}/utils/storage_radar.cpp", + "${storage_daemon_path}/utils/storage_xcollie.cpp", "${storage_daemon_path}/utils/string_utils.cpp", "${storage_daemon_path}/utils/zip_util.cpp", "${storage_service_path}/test/fuzztest/storagedaemoncreatesharefile_fuzzer/storagedaemoncreatesharefile_fuzzer.cpp", @@ -68,6 +69,7 @@ ohos_fuzztest("StorageDaemonCreateShareFileFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", + "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", "huks:libhukssdk", diff --git a/test/fuzztest/storagedaemondeletesharefile_fuzzer/BUILD.gn b/test/fuzztest/storagedaemondeletesharefile_fuzzer/BUILD.gn index 05aab455..bab136b6 100644 --- a/test/fuzztest/storagedaemondeletesharefile_fuzzer/BUILD.gn +++ b/test/fuzztest/storagedaemondeletesharefile_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("StorageDaemonDeleteShareFileFuzzTest") { "${storage_daemon_path}/utils/mount_argument_utils.cpp", "${storage_daemon_path}/utils/set_flag_utils.cpp", "${storage_daemon_path}/utils/storage_radar.cpp", + "${storage_daemon_path}/utils/storage_xcollie.cpp", "${storage_daemon_path}/utils/string_utils.cpp", "${storage_daemon_path}/utils/zip_util.cpp", "${storage_service_path}/test/fuzztest/storagedaemondeletesharefile_fuzzer/storagedaemondeletesharefile_fuzzer.cpp", @@ -68,6 +69,7 @@ ohos_fuzztest("StorageDaemonDeleteShareFileFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", + "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", "huks:libhukssdk",