From 635530b8a0b9bff1c5f91eba0da4866767f7be89 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Mon, 2 Sep 2024 22:26:03 +0800 Subject: [PATCH 1/4] test Signed-off-by: xiongchangwu --- adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp | 24 ++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index 84066fbdd..dbaf1a93f 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -303,7 +303,14 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) { for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for samgr... %{public}d", cnt); - saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (access("/data/getSaFreeze", F_OK) == 0) { + remove("/data/getSaFreeze"); + sleep(310); + } else if (access("/mnt/getSaFail", F_OK) == 0) { + saManager = nullptr; + } else { + saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + } if (saManager != nullptr) { HDF_LOGI("GetSystemAbilityManager success"); break; @@ -312,6 +319,9 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) usleep(sleepInterval); } if (saManager == nullptr) { + if (access("/mnt/getSaFail", F_OK) == 0) { + remove("/mnt/getSaFail"); + } HDF_LOGE("failed to get sa manager, waiting timeout"); return HDF_FAILURE; } @@ -326,7 +336,14 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) int ret = HDF_FAILURE; for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for addSa... %{public}d", cnt); - ret = saManager->AddSystemAbility(saId, holder->remote_); + if (access("/data/addSaFreeze", F_OK) == 0) { + remove("/data/addSaFreeze"); + sleep(310); + } else if (access("/mnt/addSaFail", F_OK) == 0) { + ret = HDF_FAILURE; + } else { + ret = saManager->AddSystemAbility(saId, holder->remote_); + } if (ret == HDF_SUCCESS) { HDF_LOGI("addsa %{public}d, success", saId); break; @@ -335,6 +352,9 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) usleep(sleepInterval); } if (ret != HDF_SUCCESS) { + if (access("/mnt/addSaFail", F_OK) == 0) { + remove("/mnt/addSaFail"); + } HDF_LOGE("failed to addSa, waiting timeout"); return ret; } -- Gitee From 3c112e3123bb86d909a170f4b6137646fe24b2f1 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Tue, 3 Sep 2024 00:17:25 +0800 Subject: [PATCH 2/4] test Signed-off-by: xiongchangwu --- adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index dbaf1a93f..70d6baa43 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -304,9 +304,11 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for samgr... %{public}d", cnt); if (access("/data/getSaFreeze", F_OK) == 0) { + HDF_LOGI("/data/getSaFreeze exist"); remove("/data/getSaFreeze"); sleep(310); - } else if (access("/mnt/getSaFail", F_OK) == 0) { + } else if (access("/data/getSaFail", F_OK) == 0) { + HDF_LOGI("/data/getSaFail exist"); saManager = nullptr; } else { saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -319,8 +321,9 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) usleep(sleepInterval); } if (saManager == nullptr) { - if (access("/mnt/getSaFail", F_OK) == 0) { - remove("/mnt/getSaFail"); + if (access("/data/getSaFail", F_OK) == 0) { + HDF_LOGI("/data/getSaFail exist a"); + remove("/data/getSaFail"); } HDF_LOGE("failed to get sa manager, waiting timeout"); return HDF_FAILURE; @@ -337,9 +340,11 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for addSa... %{public}d", cnt); if (access("/data/addSaFreeze", F_OK) == 0) { + HDF_LOGI("/data/addSaFreeze exist"); remove("/data/addSaFreeze"); sleep(310); - } else if (access("/mnt/addSaFail", F_OK) == 0) { + } else if (access("/data/addSaFail", F_OK) == 0) { + HDF_LOGI("/data/addSaFail exist"); ret = HDF_FAILURE; } else { ret = saManager->AddSystemAbility(saId, holder->remote_); @@ -352,8 +357,9 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) usleep(sleepInterval); } if (ret != HDF_SUCCESS) { - if (access("/mnt/addSaFail", F_OK) == 0) { - remove("/mnt/addSaFail"); + if (access("/data/addSaFail", F_OK) == 0) { + HDF_LOGI("/data/addSaFail exist a"); + remove("/data/addSaFail"); } HDF_LOGE("failed to addSa, waiting timeout"); return ret; -- Gitee From 24408170f972be4b470e849c004a3e6dd13ef374 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Thu, 5 Sep 2024 19:59:30 +0800 Subject: [PATCH 3/4] test Signed-off-by: xiongchangwu --- adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp | 35 ++++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index 70d6baa43..dab9854ad 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -297,6 +297,9 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) return HDF_ERR_INVALID_PARAM; } + static int addSaEnterCnt = 0; + addSaEnterCnt++; + int remove_ret = 0; const int32_t waitTimes = 50; const int32_t sleepInterval = 20000; OHOS::sptr saManager; @@ -304,11 +307,13 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for samgr... %{public}d", cnt); if (access("/data/getSaFreeze", F_OK) == 0) { - HDF_LOGI("/data/getSaFreeze exist"); - remove("/data/getSaFreeze"); + HDF_LOGI("/data/getSaFreeze exist access %{public}d", errno); + remove_ret = remove("/data/getSaFreeze"); + HDF_LOGI("/data/getSaFreeze remove %{public}d %{public}d sleep 310s", remove_ret, errno); sleep(310); + return HDF_FAILURE; } else if (access("/data/getSaFail", F_OK) == 0) { - HDF_LOGI("/data/getSaFail exist"); + HDF_LOGI("/data/getSaFail exist access %{public}d", errno); saManager = nullptr; } else { saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -317,14 +322,14 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) HDF_LOGI("GetSystemAbilityManager success"); break; } + if ((cnt == 49) && (addSaEnterCnt == 2)) { + remove_ret = remove("/data/getSaFail"); + HDF_LOGI("/data/getSaFail remove %{public}d %{public}d", remove_ret, errno); + } HDF_LOGI("GetSystemAbilityManager failed, retry"); usleep(sleepInterval); } if (saManager == nullptr) { - if (access("/data/getSaFail", F_OK) == 0) { - HDF_LOGI("/data/getSaFail exist a"); - remove("/data/getSaFail"); - } HDF_LOGE("failed to get sa manager, waiting timeout"); return HDF_FAILURE; } @@ -340,11 +345,13 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for addSa... %{public}d", cnt); if (access("/data/addSaFreeze", F_OK) == 0) { - HDF_LOGI("/data/addSaFreeze exist"); - remove("/data/addSaFreeze"); + HDF_LOGI("/data/addSaFreeze exist access %{public}d", errno); + remove_ret = remove("/data/addSaFreeze"); + HDF_LOGI("/data/addSaFreeze remove %{public}d %{public}d sleep 310s", remove_ret, errno); sleep(310); + return HDF_FAILURE; } else if (access("/data/addSaFail", F_OK) == 0) { - HDF_LOGI("/data/addSaFail exist"); + HDF_LOGI("/data/addSaFail exist access %{public}d", errno); ret = HDF_FAILURE; } else { ret = saManager->AddSystemAbility(saId, holder->remote_); @@ -353,14 +360,14 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) HDF_LOGI("addsa %{public}d, success", saId); break; } + if ((cnt == 49) && (addSaEnterCnt == 2)) { + remove_ret = remove("/data/addSaFail"); + HDF_LOGI("/data/addSaFail remove %{public}d %{public}d", remove_ret, errno); + } HDF_LOGI("AddSystemAbility failed, retry"); usleep(sleepInterval); } if (ret != HDF_SUCCESS) { - if (access("/data/addSaFail", F_OK) == 0) { - HDF_LOGI("/data/addSaFail exist a"); - remove("/data/addSaFail"); - } HDF_LOGE("failed to addSa, waiting timeout"); return ret; } -- Gitee From 0a3301242900c9fe130b1c615a3cf76e2dbdcb6d Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Tue, 12 Nov 2024 22:58:47 +0800 Subject: [PATCH 4/4] lock ioService Signed-off-by: xiongchangwu --- adapter/uhdf2/host/src/device_service_stub.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adapter/uhdf2/host/src/device_service_stub.c b/adapter/uhdf2/host/src/device_service_stub.c index 572a6336c..07e73631c 100644 --- a/adapter/uhdf2/host/src/device_service_stub.c +++ b/adapter/uhdf2/host/src/device_service_stub.c @@ -27,13 +27,12 @@ int DeviceServiceStubDispatch( struct HdfRemoteService *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply) { struct DeviceServiceStub *service = (struct DeviceServiceStub *)stub; - struct IDeviceIoService *ioService = service->super.deviceObject.service; int ret = HDF_FAILURE; #ifdef __USER__ pthread_rwlock_rdlock(&service->super.deviceObject.mutex); #endif - + struct IDeviceIoService *ioService = service->super.deviceObject.service; if (ioService == NULL) { #ifdef __USER__ pthread_rwlock_unlock(&service->super.deviceObject.mutex); -- Gitee