From 01697ad465a66a7f3f8655fcd6a1166b0d6523cb Mon Sep 17 00:00:00 2001 From: xianghengliang Date: Wed, 19 Jan 2022 16:55:13 +0800 Subject: [PATCH 1/5] add osaccount register Signed-off-by: xianghengliang --- services/distributedfiledaemon/BUILD.gn | 1 + .../include/mountpoint/mount_manager.h | 8 ++- .../src/mountpoint/mount_manager.cpp | 53 +++++++++++++++++-- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/services/distributedfiledaemon/BUILD.gn b/services/distributedfiledaemon/BUILD.gn index af0d2e294..35fe7b7d6 100755 --- a/services/distributedfiledaemon/BUILD.gn +++ b/services/distributedfiledaemon/BUILD.gn @@ -46,6 +46,7 @@ ohos_shared_library("libdistributedfiledaemon") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", + "os_account_standard:os_account_innerkits", ] configs = [ "${utils_path}:compiler_configs" ] diff --git a/services/distributedfiledaemon/include/mountpoint/mount_manager.h b/services/distributedfiledaemon/include/mountpoint/mount_manager.h index 05a4abca6..672bc58c5 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_manager.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_manager.h @@ -21,24 +21,30 @@ #include #include "mount_point.h" +#include "os_account_manager.h" #include "utils_singleton.h" namespace OHOS { namespace Storage { namespace DistributedFile { -class MountManager final : public Utils::Singleton { +class MountManager final : public Utils::Singleton, + public AccountSA::OsAccountSubscriber, + public std::enable_shared_from_this { public: void Mount(std::unique_ptr mp); void Umount(std::weak_ptr wmp); void Umount(const std::string &groupId); DECLARE_SINGLETON(MountManager); + void OnAccountsChanged(const int &id) override; private: void StartInstance() override {} void StopInstance() override {} + void RemoveMPInfoByUsrId(const int id); std::mutex serializer_; std::vector> mountPoints_; + int curUsrId{-1}; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp index 8e9792f5d..ecb57dc7a 100644 --- a/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp +++ b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp @@ -29,19 +29,65 @@ using namespace std; MountManager::MountManager() { - Mount(make_unique(Utils::MountArgumentDescriptors::Alpha())); + // OHOS::AccountSA::OsAccountSubscribeInfo osAccountSubscribeInfo; + // osAccountSubscribeInfo.SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED); + // osAccountSubscribeInfo.SetName("distributedfile"); + int err = OHOS::AccountSA::OsAccountManager::SubscribeOsAccount(shared_from_this()); + if (err != 0) { + LOGE("register os account fail err %{public}d", err); + } } MountManager::~MountManager() { try { - // Umount mountpoints in reverse order to eliminate dependencies - for_each(mountPoints_.rbegin(), mountPoints_.rend(), [this](auto &cur_mp) { Umount(cur_mp); }); + for (auto iter = mountPoints_.begin(); iter != mountPoints_.end();) { + shared_ptr smp = *iter; + auto dm = DeviceManagerAgent::GetInstance(); + dm->Recv(make_unique>>(&DeviceManagerAgent::QuitGroup, smp)); + iter = mountPoints_.erase(iter); + } + OHOS::AccountSA::OsAccountManager::UnsubscribeOsAccount(shared_from_this()); } catch (const exception &e) { LOGE("%{public}s", e.what()); } } +void MountManager::OnAccountsChanged(const int &id) +{ + LOGE("user id changed to %{public}d", id); + lock_guard lock(serializer_); + if (curUsrId != -1) { + // first stop curUsrId network + RemoveMPInfoByUsrId(curUsrId); + } + + // then start new network + curUsrId = id; + auto smp = make_shared(Utils::MountArgumentDescriptors::Alpha(id)); + auto dm = DeviceManagerAgent::GetInstance(); + dm->Recv(make_unique>>(&DeviceManagerAgent::JoinGroup, smp)); + mountPoints_.push_back(smp); +} + +void MountManager::RemoveMPInfoByUsrId(const int id) +{ + lock_guard lock(serializer_); + decltype(mountPoints_.begin()) iter = + find_if(mountPoints_.begin(), mountPoints_.end(), + [id](const auto &cur_mp) { return cur_mp->mountArg_.userId_ == id; }); + if (iter == mountPoints_.end()) { + LOGE("not find this user id %{public}d", id); + return; + } + + shared_ptr smp = *iter; + auto dm = DeviceManagerAgent::GetInstance(); + dm->Recv(make_unique>>(&DeviceManagerAgent::QuitGroup, smp)); + mountPoints_.erase(iter); + LOGE("remove mount info of user id %{public}d", id); +} + void MountManager::Mount(unique_ptr mp) { lock_guard lock(serializer_); @@ -89,6 +135,7 @@ void MountManager::Umount(weak_ptr wmp) void MountManager::Umount(const std::string &groupId) { + lock_guard lock(serializer_); if (groupId == "") { LOGE("groupId is null, no auth group to unmount"); return; -- Gitee From 1fbdec6e2a0386432c55a60da991645ad21c94b2 Mon Sep 17 00:00:00 2001 From: xianghengliang Date: Sat, 29 Jan 2022 16:04:58 +0800 Subject: [PATCH 2/5] add multiuser switch observer Signed-off-by: xianghengliang --- services/distributedfile.cfg | 4 +- services/distributedfiledaemon/BUILD.gn | 1 + .../include/device/device_manager_agent.h | 5 +- .../include/ipc/daemon.h | 1 + .../include/mountpoint/mount_manager.h | 10 +- .../include/mountpoint/mount_point.h | 9 +- .../include/multiuser/os_account_observer.h | 48 +++++++ .../include/network/network_agent_template.h | 5 +- .../include/network/softbus/softbus_agent.h | 1 + .../src/device/device_manager_agent.cpp | 122 ++++++------------ .../distributedfiledaemon/src/ipc/daemon.cpp | 21 ++- .../src/mountpoint/mount_manager.cpp | 107 +-------------- .../src/mountpoint/mount_point.cpp | 41 +----- .../src/multiuser/os_account_observer.cpp | 91 +++++++++++++ .../src/network/network_agent_template.cpp | 3 - utils/system/include/utils_mount_argument.h | 8 +- utils/system/src/utils_mount_argument.cpp | 59 ++------- 17 files changed, 230 insertions(+), 306 deletions(-) create mode 100644 services/distributedfiledaemon/include/multiuser/os_account_observer.h create mode 100644 services/distributedfiledaemon/src/multiuser/os_account_observer.cpp diff --git a/services/distributedfile.cfg b/services/distributedfile.cfg index e2e31e540..442e2113f 100644 --- a/services/distributedfile.cfg +++ b/services/distributedfile.cfg @@ -20,8 +20,8 @@ },{ "name": "distributedfiledaemon", "path": ["/system/bin/sa_main", "/system/profile/distributedfiledaemon.xml"], - "uid": "root", - "gid": ["root"], + "uid": "system", + "gid": ["system"], "caps": ["SYS_PTRACE", "KILL"] }] } diff --git a/services/distributedfiledaemon/BUILD.gn b/services/distributedfiledaemon/BUILD.gn index 35fe7b7d6..ce3d8c637 100755 --- a/services/distributedfiledaemon/BUILD.gn +++ b/services/distributedfiledaemon/BUILD.gn @@ -28,6 +28,7 @@ ohos_shared_library("libdistributedfiledaemon") { "src/ipc/daemon_stub.cpp", "src/mountpoint/mount_manager.cpp", "src/mountpoint/mount_point.cpp", + "src/multiuser/os_account_observer.cpp", "src/network/kernel_talker.cpp", "src/network/network_agent_template.cpp", "src/network/session_pool.cpp", diff --git a/services/distributedfiledaemon/include/device/device_manager_agent.h b/services/distributedfiledaemon/include/device/device_manager_agent.h index ef5fdc57a..470704d29 100644 --- a/services/distributedfiledaemon/include/device/device_manager_agent.h +++ b/services/distributedfiledaemon/include/device/device_manager_agent.h @@ -69,7 +69,6 @@ public: void OfflineAllDevice(); void ReconnectOnlineDevices(); - void AuthGroupOnlineProc(const DeviceInfo info); void OnRemoteDied() override; DeviceInfo &GetLocalDeviceInfo(); @@ -83,15 +82,15 @@ private: void RegisterToExternalDm(); void UnregisterFromExternalDm(); - void AuthGroupOfflineProc(const DeviceInfo &info); void QueryRelatedGroups(const std::string &udid, std::vector &groupList); bool CheckIsAuthGroup(const GroupInfo &group); - void AllAuthGroupsOfflineProc(); + std::shared_ptr FindNetworkBaseTrustRelation(bool isAccountless); // We use a mutex instead of a shared_mutex to serialize online/offline procedures std::mutex mpToNetworksMutex_; std::map> mpToNetworks_; DeviceInfo localDeviceInfo_; + std::unordered_map> cidNetTypeRecord_; // cid-->same_account/accoutless's network // key:groupId val:groupIdMark, the set of networkId std::unordered_map>> authGroupMap_; }; diff --git a/services/distributedfiledaemon/include/ipc/daemon.h b/services/distributedfiledaemon/include/ipc/daemon.h index 32283511c..b89ba7501 100644 --- a/services/distributedfiledaemon/include/ipc/daemon.h +++ b/services/distributedfiledaemon/include/ipc/daemon.h @@ -53,6 +53,7 @@ private: void PublishSA(); void StartManagers(); + void RegisterOsAcount(); }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/include/mountpoint/mount_manager.h b/services/distributedfiledaemon/include/mountpoint/mount_manager.h index 672bc58c5..c1509570c 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_manager.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_manager.h @@ -21,26 +21,24 @@ #include #include "mount_point.h" -#include "os_account_manager.h" #include "utils_singleton.h" +#include "utils_log.h" namespace OHOS { namespace Storage { namespace DistributedFile { -class MountManager final : public Utils::Singleton, - public AccountSA::OsAccountSubscriber, - public std::enable_shared_from_this { +class MountManager final : public Utils::Singleton, public std::enable_shared_from_this { public: + void RegisterOsAcount(); void Mount(std::unique_ptr mp); void Umount(std::weak_ptr wmp); void Umount(const std::string &groupId); DECLARE_SINGLETON(MountManager); - void OnAccountsChanged(const int &id) override; + void RemoveMPInfoByUsrId(const int id); private: void StartInstance() override {} void StopInstance() override {} - void RemoveMPInfoByUsrId(const int id); std::mutex serializer_; std::vector> mountPoints_; diff --git a/services/distributedfiledaemon/include/mountpoint/mount_point.h b/services/distributedfiledaemon/include/mountpoint/mount_point.h index e6a9a84a2..6103dad3e 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_point.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_point.h @@ -35,23 +35,22 @@ public: return id_; }; - std::string GetAuthGroupId() const + bool isAccountLess() const { - return authGroupId_; - } + return mountArg_.accountless_; + }; std::string ToString() const; Utils::MountArgument GetMountArgument() const; bool operator==(const MountPoint &rop) const; private: - friend class MountManager; + friend class osAccountChangeObserver; Utils::MountArgument mountArg_; void Mount() const; void Umount() const; static std::atomic idGen_; uint32_t id_{0}; - std::string authGroupId_{""}; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/include/multiuser/os_account_observer.h b/services/distributedfiledaemon/include/multiuser/os_account_observer.h new file mode 100644 index 000000000..b360c57a5 --- /dev/null +++ b/services/distributedfiledaemon/include/multiuser/os_account_observer.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021 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 ACCOUNT_CHANGE_OBSERVER_H +#define ACCOUNT_CHANGE_OBSERVER_H + +#include +#include +#include + +#include "mountpoint/mount_point.h" +#include "os_account_manager.h" + +namespace OHOS { +namespace Storage { +namespace DistributedFile { +static constexpr int MOUNT_POINT_NUM = 2; +class osAccountChangeObserver final : public AccountSA::OsAccountSubscriber { +public: + osAccountChangeObserver() = default; + ~osAccountChangeObserver(); + explicit osAccountChangeObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo); + + void OnAccountsChanged(const int &id) override; +private: + void RemoveMPInfo(const int id); + void AddMPInfo(const int id, const std::string &relativePath); + + std::mutex serializer_; + std::unordered_map>> mountPoints_; + int curUsrId{-1}; +}; +} // namespace DistributedFile +} // namespace Storage +} // namespace OHOS +#endif // ACCOUNT_CHANGE_OBSERVER_H \ No newline at end of file diff --git a/services/distributedfiledaemon/include/network/network_agent_template.h b/services/distributedfiledaemon/include/network/network_agent_template.h index d878472cb..b3a8b7262 100644 --- a/services/distributedfiledaemon/include/network/network_agent_template.h +++ b/services/distributedfiledaemon/include/network/network_agent_template.h @@ -52,7 +52,10 @@ public: void ConnectDeviceAsync(const DeviceInfo info); void DisconnectDevice(const DeviceInfo info); void AcceptSession(std::shared_ptr session); - + std::shared_ptr GetMountPoint() + { + return mountPoint_.lock(); + }; protected: virtual void JoinDomain() = 0; virtual void QuitDomain() = 0; diff --git a/services/distributedfiledaemon/include/network/softbus/softbus_agent.h b/services/distributedfiledaemon/include/network/softbus/softbus_agent.h index 28d88c4b7..ed757c315 100644 --- a/services/distributedfiledaemon/include/network/softbus/softbus_agent.h +++ b/services/distributedfiledaemon/include/network/softbus/softbus_agent.h @@ -42,6 +42,7 @@ private: std::map OpenSessionRetriedTimesMap_; std::string sessionName_; + // bool accountless_{false}; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index 25e12ff25..d4d9679d0 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -91,7 +91,7 @@ void DeviceManagerAgent::JoinGroup(weak_ptr mp) throw runtime_error(ss.str()); } } - LOGI("smp id %{public}d, groupId %{public}s", smp->GetID(), smp->GetAuthGroupId().c_str()); + LOGI("smp id %{public}d", smp->GetID()); agent->StartActor(); } @@ -140,22 +140,40 @@ void DeviceManagerAgent::ReconnectOnlineDevices() } } +std::shared_ptr DeviceManagerAgent::FindNetworkBaseTrustRelation(bool isAccountless) +{ + for (auto [ignore, net] : mpToNetworks_) { + if (net->GetMountPoint()->isAccountLess() == isAccountless) { + return net; + } + } + return nullptr; +} + void DeviceManagerAgent::OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) { LOGI("netwrorkId %{public}s, OnDeviceOnline begin", deviceInfo.deviceId); + // 先检查 认证群组信息, 并將此cid是否是同账号信息记录到map中 DeviceInfo info(deviceInfo); - { - unique_lock lock(mpToNetworksMutex_); - for (auto &&networkAgent : mpToNetworks_) { - auto cmd = make_unique>( - &NetworkAgentTemplate::ConnectDeviceAsync, info); - cmd->UpdateOption({ - .tryTimes_ = MAX_RETRY_COUNT, - }); - networkAgent.second->Recv(move(cmd)); + std::vector groupList; + QueryRelatedGroups(info.udid_, groupList); + unique_lock lock(mpToNetworksMutex_); + for (const auto &group : groupList) { + if (CheckIsAuthGroup(group)) { + cidNetTypeRecord_.insert({info.cid_, FindNetworkBaseTrustRelation(true)}); // accountless == true + } else { + cidNetTypeRecord_.insert({info.cid_, FindNetworkBaseTrustRelation(false)}); } } - AuthGroupOnlineProc(info); + // 如果是同账号的,则只让同账号的去建链,所以在创建群组时就要区分出是否是同账号的 + // 如果是异账号,则只让异账号建链 + auto networkAgent = cidNetTypeRecord_[info.cid_]; + auto cmd = make_unique>( + &NetworkAgentTemplate::ConnectDeviceAsync, info); + cmd->UpdateOption({ + .tryTimes_ = MAX_RETRY_COUNT, + }); + networkAgent->Recv(move(cmd)); LOGI("OnDeviceOnline end"); } @@ -164,18 +182,14 @@ void DeviceManagerAgent::OnDeviceOffline(const DistributedHardware::DmDeviceInfo { LOGI("OnDeviceOffline begin"); DeviceInfo info(deviceInfo); - { - unique_lock lock(mpToNetworksMutex_); - for (auto &&networkAgent : mpToNetworks_) { - auto cmd = - make_unique>(&NetworkAgentTemplate::DisconnectDevice, info); - cmd->UpdateOption({ - .tryTimes_ = 1, - }); - networkAgent.second->Recv(move(cmd)); - } - } - AuthGroupOfflineProc(info); + + unique_lock lock(mpToNetworksMutex_); + auto networkAgent = cidNetTypeRecord_[info.cid_]; + auto cmd = make_unique>(&NetworkAgentTemplate::DisconnectDevice, info); + networkAgent->Recv(move(cmd)); + cidNetTypeRecord_.erase(info.cid_); + + // AuthGroupOfflineProc(info); LOGI("OnDeviceOffline end"); } @@ -242,67 +256,6 @@ void DeviceManagerAgent::QueryRelatedGroups(const std::string &udid, std::vector return; } -void DeviceManagerAgent::AuthGroupOnlineProc(const DeviceInfo info) -{ - std::vector groupList; - QueryRelatedGroups(info.udid_, groupList); - for (const auto &group : groupList) { - if (!CheckIsAuthGroup(group)) { - continue; - } - if (authGroupMap_.find(group.groupId) == authGroupMap_.end()) { - LOGI("groupId %{public}s not exist, map size %{public}d, then mount", group.groupId.c_str(), - authGroupMap_.size()); - std::stringstream ss; - ss << "groupId_" << authGroupMap_.size(); - MountManager::GetInstance()->Mount(make_unique( - Utils::MountArgumentDescriptors::SetAuthGroupMountArgument(ss.str(), group.groupOwner, true))); - std::get<0>(authGroupMap_[group.groupId]) = ss.str(); - } - auto [iter, status] = std::get<1>(authGroupMap_[group.groupId]).insert(info.cid_); - if (status == false) { - LOGI("cid %{public}s has already inserted into groupId %{public}s", info.cid_.c_str(), - group.groupId.c_str()); - continue; - } - } -} - -void DeviceManagerAgent::AuthGroupOfflineProc(const DeviceInfo &info) -{ - for (auto iter = authGroupMap_.begin(); iter != authGroupMap_.end();) { - auto [groupIdMark, set] = iter->second; - auto groupId = iter->first; - if (set.find(info.GetCid()) == set.end()) { - continue; - } - - if (authGroupMap_.find(groupId) == authGroupMap_.end()) { - LOGI("can not find groupId %{public}s ", groupId.c_str()); - continue; - } - std::get<1>(authGroupMap_[groupId]).erase(info.GetCid()); - if (std::get<1>(authGroupMap_[groupId]).empty()) { - std::vector groupList; - if (groupList.size() == 0) { - MountManager::GetInstance()->Umount(groupIdMark); - iter = authGroupMap_.erase(iter); - continue; - } - } - iter++; - } -} - -void DeviceManagerAgent::AllAuthGroupsOfflineProc() -{ - for (auto iter = authGroupMap_.begin(); iter != authGroupMap_.end();) { - auto [groupIdMark, ignore] = iter->second; - MountManager::GetInstance()->Umount(groupIdMark); - authGroupMap_.erase(iter++); - } -} - bool DeviceManagerAgent::CheckIsAuthGroup(const GroupInfo &group) { if (group.groupType == PEER_TO_PEER_GROUP || group.groupType == ACROSS_ACCOUNT_AUTHORIZE_GROUP) { @@ -331,7 +284,6 @@ void DeviceManagerAgent::OnRemoteDied() LOGI("device manager service died"); StopInstance(); OfflineAllDevice(); // cannot commit a cmd to queue - AllAuthGroupsOfflineProc(); StartInstance(); ReconnectOnlineDevices(); } diff --git a/services/distributedfiledaemon/src/ipc/daemon.cpp b/services/distributedfiledaemon/src/ipc/daemon.cpp index 2db0236d3..982eef1e3 100644 --- a/services/distributedfiledaemon/src/ipc/daemon.cpp +++ b/services/distributedfiledaemon/src/ipc/daemon.cpp @@ -16,6 +16,8 @@ #include "ipc/daemon.h" #include "mountpoint/mount_manager.h" +#include "multiuser/os_account_observer.h" +#include "os_account_manager.h" #include "system_ability_definition.h" #include "utils_log.h" @@ -39,9 +41,23 @@ void Daemon::PublishSA() LOGI("Init finished successfully"); } +void Daemon::RegisterOsAcount() +{ + OHOS::AccountSA::OsAccountSubscribeInfo osAccountSubscribeInfo; + osAccountSubscribeInfo.SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED); + osAccountSubscribeInfo.SetName("distributed_file_service"); + + auto subScriber = std::make_shared(osAccountSubscribeInfo); + int ret = OHOS::AccountSA::OsAccountManager::SubscribeOsAccount(subScriber); + if (ret != 0) { + LOGE("register os account fail ret %{public}d", ret); + } + LOGI("register os account success, ret %{public}d", ret); +} + void Daemon::StartManagers() { - MountManager::GetInstance(); + // MountManager::GetInstance()->RegisterOsAcount(); } void Daemon::OnStart() @@ -54,7 +70,8 @@ void Daemon::OnStart() try { PublishSA(); - StartManagers(); + // StartManagers(); + RegisterOsAcount(); } catch (const exception &e) { LOGE("%{public}s", e.what()); } diff --git a/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp index ecb57dc7a..0dc7bccdd 100644 --- a/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp +++ b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp @@ -29,128 +29,23 @@ using namespace std; MountManager::MountManager() { - // OHOS::AccountSA::OsAccountSubscribeInfo osAccountSubscribeInfo; - // osAccountSubscribeInfo.SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED); - // osAccountSubscribeInfo.SetName("distributedfile"); - int err = OHOS::AccountSA::OsAccountManager::SubscribeOsAccount(shared_from_this()); - if (err != 0) { - LOGE("register os account fail err %{public}d", err); - } -} - -MountManager::~MountManager() -{ - try { - for (auto iter = mountPoints_.begin(); iter != mountPoints_.end();) { - shared_ptr smp = *iter; - auto dm = DeviceManagerAgent::GetInstance(); - dm->Recv(make_unique>>(&DeviceManagerAgent::QuitGroup, smp)); - iter = mountPoints_.erase(iter); - } - OHOS::AccountSA::OsAccountManager::UnsubscribeOsAccount(shared_from_this()); - } catch (const exception &e) { - LOGE("%{public}s", e.what()); - } -} - -void MountManager::OnAccountsChanged(const int &id) -{ - LOGE("user id changed to %{public}d", id); - lock_guard lock(serializer_); - if (curUsrId != -1) { - // first stop curUsrId network - RemoveMPInfoByUsrId(curUsrId); - } - // then start new network - curUsrId = id; - auto smp = make_shared(Utils::MountArgumentDescriptors::Alpha(id)); - auto dm = DeviceManagerAgent::GetInstance(); - dm->Recv(make_unique>>(&DeviceManagerAgent::JoinGroup, smp)); - mountPoints_.push_back(smp); } -void MountManager::RemoveMPInfoByUsrId(const int id) +MountManager::~MountManager() { - lock_guard lock(serializer_); - decltype(mountPoints_.begin()) iter = - find_if(mountPoints_.begin(), mountPoints_.end(), - [id](const auto &cur_mp) { return cur_mp->mountArg_.userId_ == id; }); - if (iter == mountPoints_.end()) { - LOGE("not find this user id %{public}d", id); - return; - } - - shared_ptr smp = *iter; - auto dm = DeviceManagerAgent::GetInstance(); - dm->Recv(make_unique>>(&DeviceManagerAgent::QuitGroup, smp)); - mountPoints_.erase(iter); - LOGE("remove mount info of user id %{public}d", id); } void MountManager::Mount(unique_ptr mp) { - lock_guard lock(serializer_); - - shared_ptr smp = move(mp); - - auto isExisted = [smp](const auto &cur_mp) { return *smp == *cur_mp; }; - if (!smp || any_of(mountPoints_.begin(), mountPoints_.end(), isExisted)) { - stringstream ss; - ss << "Mount an empty/existent mountpoint" << (smp ? smp->GetMountArgument().GetFullDst() : ""); - LOGE("%{public}s", ss.str().c_str()); - throw runtime_error(ss.str()); - } - try { - smp->Umount(); // try umount one time - } catch (const exception &e) { - LOGE("%{public}s", e.what()); - } - smp->Mount(); - auto dm = DeviceManagerAgent::GetInstance(); - dm->Recv(make_unique>>(&DeviceManagerAgent::JoinGroup, smp)); - mountPoints_.push_back(smp); } void MountManager::Umount(weak_ptr wmp) { - auto smp = wmp.lock(); - lock_guard lock(serializer_); - - decltype(mountPoints_.begin()) it; - auto isExisted = [smp](const auto &cur_mp) { return *smp == *cur_mp; }; - if (!smp || ((it = find_if(mountPoints_.begin(), mountPoints_.end(), isExisted)) == mountPoints_.end())) { - stringstream ss; - ss << "Umount an empty/non-existent mountpoint" << (smp ? smp->GetMountArgument().GetFullDst() : ""); - LOGE("%{public}s", ss.str().c_str()); - throw runtime_error(ss.str()); - } - LOGI("Umount begin"); - smp->Umount(); - auto dm = DeviceManagerAgent::GetInstance(); - dm->Recv(make_unique>>(&DeviceManagerAgent::QuitGroup, smp)); - mountPoints_.erase(it); - LOGI("Umount end"); } void MountManager::Umount(const std::string &groupId) { - lock_guard lock(serializer_); - if (groupId == "") { - LOGE("groupId is null, no auth group to unmount"); - return; - } - - decltype(mountPoints_.begin()) iter = - find_if(mountPoints_.begin(), mountPoints_.end(), - [groupId](const auto &cur_mp) { return cur_mp->authGroupId_ == groupId; }); - if (iter == mountPoints_.end()) { - stringstream ss; - ss << "Umount not find this auth group id" << groupId; - LOGE("Umount not find this auth group id %{public}s", groupId.c_str()); - throw runtime_error(ss.str()); - } - Umount(*iter); } } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/src/mountpoint/mount_point.cpp b/services/distributedfiledaemon/src/mountpoint/mount_point.cpp index 1586751ea..a6a9c1d57 100644 --- a/services/distributedfiledaemon/src/mountpoint/mount_point.cpp +++ b/services/distributedfiledaemon/src/mountpoint/mount_point.cpp @@ -31,53 +31,16 @@ atomic MountPoint::idGen_; MountPoint::MountPoint(const Utils::MountArgument &mountArg) : mountArg_(mountArg) { id_ = idGen_++; - if (mountArg.accountless_) { - authGroupId_ = mountArg.groupId_; - } } void MountPoint::Mount() const { - auto mntArg = GetMountArgument(); - - string src = mntArg.GetFullSrc(); - Utils::ForceCreateDirectory(src, S_IRWXU | S_IRWXG | S_IXOTH, Utils::UID_SYSTEM, Utils::UID_MEDIA_RW); - - string dst = mntArg.GetFullDst(); - Utils::ForceCreateDirectory(dst, S_IRWXU | S_IRWXG | S_IXOTH); - - string cache = mntArg.GetCachePath(); - Utils::ForceCreateDirectory(cache, S_IRWXU | S_IRWXG | S_IXOTH); - - string data = mntArg.GetDataPath(); - Utils::ForceCreateDirectory(data, S_IRWXU | S_IRWXG | S_IXOTH); - - unsigned long flags = mntArg.GetFlags(); - string options = mntArg.OptionsToString(); - int ret = mount(src.c_str(), dst.c_str(), "hmdfs", flags, options.c_str()); - if (ret == -1 && errno != EEXIST && errno != EBUSY) { - auto cond = system_category().default_error_condition(errno); - LOGE("Failed to mount: %{public}d %{public}s", cond.value(), cond.message().c_str()); - throw system_error(errno, system_category()); - } - LOGI("mount sucess: src %{public}s --> dst %{public}s", src.c_str(), dst.c_str()); - - if (mntArg.accountless_) { - Utils::ForceCreateDirectory(dst + "/device_view/local/data/" + mntArg.packageName_, - S_IRWXU | S_IRWXG | S_IXOTH); - } + LOGI("mount"); } void MountPoint::Umount() const { - string dst = GetMountArgument().GetFullDst(); - if (umount2(dst.c_str(), MNT_DETACH) == -1) { - auto cond = system_category().default_error_condition(errno); - LOGE("Failed to umount: %{public}d %{public}s", cond.value(), cond.message().c_str()); - throw system_error(errno, system_category()); - } - - Utils::ForceRemoveDirectory(dst); + LOGE("umount"); } bool MountPoint::operator==(const MountPoint &rop) const diff --git a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp new file mode 100644 index 000000000..6dfc45ee8 --- /dev/null +++ b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 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 "multiuser/os_account_observer.h" + +#include +#include + +#include "device/device_manager_agent.h" +#include "utils_log.h" +#include "utils_mount_argument.h" + +namespace OHOS { +namespace Storage { +namespace DistributedFile { +using namespace std; +namespace { +static const std::string SAME_ACCOUNT = "account"; +static const std::string ACCOUNT_LESS = "no_account"; +} // namespace + +osAccountChangeObserver::osAccountChangeObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo) : OsAccountSubscriber(subscribeInfo) +{ + LOGI("init first to create network of user 100"); + // lock_guard lock(serializer_); + curUsrId = 100; + AddMPInfo(curUsrId, SAME_ACCOUNT); + AddMPInfo(curUsrId, ACCOUNT_LESS); + LOGI("init first to create network of user 100, done"); +} + +osAccountChangeObserver::~osAccountChangeObserver() +{ + // OHOS::AccountSA::OsAccountManager::UnsubscribeOsAccount(shared_from_this()); +} + +void osAccountChangeObserver::AddMPInfo(const int id, const std::string &relativePath) +{ + auto smp = make_shared(Utils::MountArgumentDescriptors::Alpha(id, relativePath)); + auto dm = DeviceManagerAgent::GetInstance(); + dm->Recv(make_unique>>(&DeviceManagerAgent::JoinGroup, smp)); + mountPoints_[id].emplace_back(smp); +} + +void osAccountChangeObserver::OnAccountsChanged(const int &id) +{ + LOGI("user id changed to %{public}d", id); + lock_guard lock(serializer_); + if (curUsrId != -1) { // todo: 仅仅是切断当前用户,是否需要删除之前的用户信息? + // first stop curUsrId network + RemoveMPInfo(curUsrId); + } + + // then start new network + curUsrId = id; + AddMPInfo(id, SAME_ACCOUNT); + AddMPInfo(id, ACCOUNT_LESS); + LOGI("user id %{public}d, add network done", curUsrId); +} + +void osAccountChangeObserver::RemoveMPInfo(const int id) +{ + auto iter = mountPoints_.find(id); + if (iter == mountPoints_.end()) { + LOGE("user id %{public}d not find in map", curUsrId); + return; + } + + auto dm = DeviceManagerAgent::GetInstance(); + for (auto smp : iter->second) { + dm->Recv(make_unique>>(&DeviceManagerAgent::QuitGroup, smp)); + } + mountPoints_.erase(iter); + + LOGE("remove mount info of user id %{public}d", id); +} +} // namespace DistributedFile +} // namespace Storage +} // namespace OHOS \ No newline at end of file diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index 507b28782..c244fcda8 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -60,9 +60,6 @@ void NetworkAgentTemplate::ConnectOnlineDevices() .tryTimes_ = MAX_RETRY_COUNT, }); Recv(move(cmd)); - - dma->Recv( - make_unique>(&DeviceManagerAgent::AuthGroupOnlineProc, info)); } } diff --git a/utils/system/include/utils_mount_argument.h b/utils/system/include/utils_mount_argument.h index 2047fdd89..10ad193aa 100644 --- a/utils/system/include/utils_mount_argument.h +++ b/utils/system/include/utils_mount_argument.h @@ -25,7 +25,6 @@ namespace Utils { struct MountArgument final { int userId_{0}; bool accountless_{false}; - std::string groupId_; bool needInitDir_{false}; bool useCache_{false}; bool caseSensitive_{false}; @@ -33,22 +32,19 @@ struct MountArgument final { bool enableFixupOwnerShip_{false}; bool enableOfflineStash_{true}; bool externalFS_{false}; - std::string packageName_; + std::string relativePath_; std::string GetFullSrc() const; std::string GetFullDst() const; std::string GetCtrlPath() const; std::string GetCachePath() const; std::string OptionsToString() const; - std::string GetDataPath() const; unsigned long GetFlags() const; }; class MountArgumentDescriptors final { public: - static MountArgument Alpha(int userId = 0); - static MountArgument - SetAuthGroupMountArgument(const std::string &groupId, const std::string &packageName, bool accountless); + static MountArgument Alpha(int userId, std::string relativePath); }; } // namespace Utils } // namespace DistributedFile diff --git a/utils/system/src/utils_mount_argument.cpp b/utils/system/src/utils_mount_argument.cpp index c45a60c1c..70aefe122 100644 --- a/utils/system/src/utils_mount_argument.cpp +++ b/utils/system/src/utils_mount_argument.cpp @@ -26,51 +26,27 @@ using namespace std; namespace { static const std::string DATA_POINT = "/data/service/el2/"; static const std::string BASE_MOUNT_POINT = "/mnt/hmdfs/"; -static const std::string AUTH_GROUP_MOUNT_POINT = "/mnt/hmdfs/auth_groups/"; static const std::string SYSFS_HMDFS_PATH = "sys/fs/hmdfs/"; } // namespace string MountArgument::GetFullSrc() const { stringstream ss; - if (!accountless_) { - ss << DATA_POINT << userId_ << "/hmdfs"; - } else { - ss << DATA_POINT << userId_ << "/hmdfs/auth_groups/" << groupId_; - } + ss << DATA_POINT << userId_ << "/hmdfs/" << relativePath_; return ss.str(); } string MountArgument::GetFullDst() const { stringstream ss; - if (!accountless_) { - ss << BASE_MOUNT_POINT << userId_ << "/"; - } else { - ss << AUTH_GROUP_MOUNT_POINT << groupId_ << "/"; - } + ss << BASE_MOUNT_POINT << userId_ << "/" << relativePath_; return ss.str(); } string MountArgument::GetCachePath() const { stringstream ss; - if (!accountless_) { - ss << DATA_POINT << userId_ << "/hmdfs/cache/"; - } else { - ss << DATA_POINT << userId_ << "/hmdfs/auth_groups/" << groupId_ << "/cache/"; - } - return ss.str(); -} - -string MountArgument::GetDataPath() const -{ - stringstream ss; - if (!accountless_) { - ss << DATA_POINT << userId_ << "/hmdfs/data/"; - } else { - ss << DATA_POINT << userId_ << "/hmdfs/auth_groups/" << groupId_ << "/data/"; - } + ss << DATA_POINT << userId_ << "/hmdfs/" << relativePath_ << "/cache/"; return ss.str(); } @@ -124,36 +100,23 @@ unsigned long MountArgument::GetFlags() const return MS_NODEV; } -MountArgument MountArgumentDescriptors::Alpha(int userId) +MountArgument MountArgumentDescriptors::Alpha(int userId, string relativePath) { MountArgument mountArgument = { - .groupId_ = "default", + .userId_ = userId, .needInitDir_ = true, .useCache_ = true, .enableMergeView_ = true, .enableFixupOwnerShip_ = false, .enableOfflineStash_ = true, .externalFS_ = false, + .relativePath_ = relativePath, }; - mountArgument.userId_ = userId; - return mountArgument; -} - -MountArgument MountArgumentDescriptors::SetAuthGroupMountArgument(const std::string &groupId, - const std::string &packageName, - bool accountless) -{ - MountArgument mountArgument = { - .accountless_ = accountless, - .groupId_ = groupId, - .needInitDir_ = true, - .useCache_ = true, - .enableMergeView_ = true, - .enableFixupOwnerShip_ = false, - .enableOfflineStash_ = true, - .externalFS_ = false, - .packageName_ = packageName, - }; + if (relativePath == "account") { + mountArgument.accountless_ = false; + } else { + mountArgument.accountless_ = true; + } return mountArgument; } } // namespace Utils -- Gitee From b0488dbec298c9f954802b3864848c985d4ef8b0 Mon Sep 17 00:00:00 2001 From: xianghengliang Date: Sat, 5 Feb 2022 11:53:39 +0800 Subject: [PATCH 3/5] dev trust relation info logic Signed-off-by: xianghengliang --- .../include/device/device_manager_agent.h | 2 +- .../include/ipc/daemon.h | 3 +- .../src/device/device_manager_agent.cpp | 54 +++++++++++-------- .../distributedfiledaemon/src/ipc/daemon.cpp | 10 +--- .../src/multiuser/os_account_observer.cpp | 4 +- .../src/network/kernel_talker.cpp | 3 +- utils/system/src/utils_mount_argument.cpp | 5 +- 7 files changed, 42 insertions(+), 39 deletions(-) diff --git a/services/distributedfiledaemon/include/device/device_manager_agent.h b/services/distributedfiledaemon/include/device/device_manager_agent.h index 470704d29..d70fcec47 100644 --- a/services/distributedfiledaemon/include/device/device_manager_agent.h +++ b/services/distributedfiledaemon/include/device/device_manager_agent.h @@ -82,7 +82,7 @@ private: void RegisterToExternalDm(); void UnregisterFromExternalDm(); - void QueryRelatedGroups(const std::string &udid, std::vector &groupList); + void QueryRelatedGroups(const std::string &udid, const std::string &networkId); bool CheckIsAuthGroup(const GroupInfo &group); std::shared_ptr FindNetworkBaseTrustRelation(bool isAccountless); // We use a mutex instead of a shared_mutex to serialize online/offline procedures diff --git a/services/distributedfiledaemon/include/ipc/daemon.h b/services/distributedfiledaemon/include/ipc/daemon.h index b89ba7501..d5326ac4e 100644 --- a/services/distributedfiledaemon/include/ipc/daemon.h +++ b/services/distributedfiledaemon/include/ipc/daemon.h @@ -52,8 +52,7 @@ private: bool registerToService_{false}; void PublishSA(); - void StartManagers(); - void RegisterOsAcount(); + void RegisterOsAccount(); }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index d4d9679d0..a9bc92959 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -91,7 +91,7 @@ void DeviceManagerAgent::JoinGroup(weak_ptr mp) throw runtime_error(ss.str()); } } - LOGI("smp id %{public}d", smp->GetID()); + LOGI("smp id %{public}d, is account_less %{pubulic}d", smp->GetID(), agent->GetMountPoint()->isAccountLess()); agent->StartActor(); } @@ -119,55 +119,50 @@ void DeviceManagerAgent::QuitGroup(weak_ptr mp) void DeviceManagerAgent::OfflineAllDevice() { unique_lock lock(mpToNetworksMutex_); - for (auto &&networkAgent : mpToNetworks_) { + for (auto [ignore, net] : cidNetTypeRecord_) { auto cmd = make_unique>(&NetworkAgentTemplate::DisconnectAllDevices); - cmd->UpdateOption({ - .tryTimes_ = 1, - }); - networkAgent.second->Recv(move(cmd)); + net->Recv(move(cmd)); } } void DeviceManagerAgent::ReconnectOnlineDevices() { unique_lock lock(mpToNetworksMutex_); - for (auto &&networkAgent : mpToNetworks_) { + for (auto [ignore, net] : cidNetTypeRecord_) { auto cmd = make_unique>(&NetworkAgentTemplate::ConnectOnlineDevices); cmd->UpdateOption({ .tryTimes_ = MAX_RETRY_COUNT, }); - networkAgent.second->Recv(move(cmd)); + net->Recv(move(cmd)); } } std::shared_ptr DeviceManagerAgent::FindNetworkBaseTrustRelation(bool isAccountless) { + LOGI("enter: isAccountless %{public}d", isAccountless); for (auto [ignore, net] : mpToNetworks_) { if (net->GetMountPoint()->isAccountLess() == isAccountless) { return net; } } + LOGE("not find this net in mpToNetworks, isAccountless %{public}d", isAccountless); return nullptr; } void DeviceManagerAgent::OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) { - LOGI("netwrorkId %{public}s, OnDeviceOnline begin", deviceInfo.deviceId); - // 先检查 认证群组信息, 并將此cid是否是同账号信息记录到map中 + LOGI("networkId %{public}s, OnDeviceOnline begin", deviceInfo.deviceId); + // online first query this dev's trust info, 先检查 认证群组信息, 并將此cid是否是同账号信息记录到map中 DeviceInfo info(deviceInfo); - std::vector groupList; - QueryRelatedGroups(info.udid_, groupList); + QueryRelatedGroups(info.udid_, info.cid_); + + // based on dev's trust info, choose corresponding network agent to obtain socket unique_lock lock(mpToNetworksMutex_); - for (const auto &group : groupList) { - if (CheckIsAuthGroup(group)) { - cidNetTypeRecord_.insert({info.cid_, FindNetworkBaseTrustRelation(true)}); // accountless == true - } else { - cidNetTypeRecord_.insert({info.cid_, FindNetworkBaseTrustRelation(false)}); - } - } - // 如果是同账号的,则只让同账号的去建链,所以在创建群组时就要区分出是否是同账号的 - // 如果是异账号,则只让异账号建链 auto networkAgent = cidNetTypeRecord_[info.cid_]; + if (networkAgent == nullptr) { + LOGE("cid %{public}s network is null!", info.cid_.c_str()); + return; + } auto cmd = make_unique>( &NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption({ @@ -185,6 +180,10 @@ void DeviceManagerAgent::OnDeviceOffline(const DistributedHardware::DmDeviceInfo unique_lock lock(mpToNetworksMutex_); auto networkAgent = cidNetTypeRecord_[info.cid_]; + if (networkAgent == nullptr) { + LOGE("cid %{public}s network is null!", info.cid_.c_str()); + return; + } auto cmd = make_unique>(&NetworkAgentTemplate::DisconnectDevice, info); networkAgent->Recv(move(cmd)); cidNetTypeRecord_.erase(info.cid_); @@ -212,7 +211,7 @@ void from_json(const nlohmann::json &jsonObject, GroupInfo &groupInfo) } } -void DeviceManagerAgent::QueryRelatedGroups(const std::string &udid, std::vector &groupList) +void DeviceManagerAgent::QueryRelatedGroups(const std::string &udid, const std::string &networkId) { LOGI("use udid %{public}s query hichain related groups", udid.c_str()); int ret = InitDeviceAuthService(); @@ -248,11 +247,22 @@ void DeviceManagerAgent::QueryRelatedGroups(const std::string &udid, std::vector return; } + std::vector groupList; groupList = jsonObject.get>(); for (auto &a : groupList) { LOGI("group info:[groupName] %{public}s, [groupId] %{public}s, [groupOwner] %{public}s,[groupType] %{public}d,", a.groupName.c_str(), a.groupId.c_str(), a.groupOwner.c_str(), a.groupType); } + + unique_lock lock(mpToNetworksMutex_); + for (const auto &group : groupList) { + if (CheckIsAuthGroup(group)) { + cidNetTypeRecord_.insert({networkId, FindNetworkBaseTrustRelation(true)}); // accountless == true + } else { + cidNetTypeRecord_.insert({networkId, FindNetworkBaseTrustRelation(false)}); + } + } + return; } diff --git a/services/distributedfiledaemon/src/ipc/daemon.cpp b/services/distributedfiledaemon/src/ipc/daemon.cpp index 982eef1e3..8bc6120ae 100644 --- a/services/distributedfiledaemon/src/ipc/daemon.cpp +++ b/services/distributedfiledaemon/src/ipc/daemon.cpp @@ -41,7 +41,7 @@ void Daemon::PublishSA() LOGI("Init finished successfully"); } -void Daemon::RegisterOsAcount() +void Daemon::RegisterOsAccount() { OHOS::AccountSA::OsAccountSubscribeInfo osAccountSubscribeInfo; osAccountSubscribeInfo.SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED); @@ -55,11 +55,6 @@ void Daemon::RegisterOsAcount() LOGI("register os account success, ret %{public}d", ret); } -void Daemon::StartManagers() -{ - // MountManager::GetInstance()->RegisterOsAcount(); -} - void Daemon::OnStart() { LOGI("Begin to start service"); @@ -70,8 +65,7 @@ void Daemon::OnStart() try { PublishSA(); - // StartManagers(); - RegisterOsAcount(); + RegisterOsAccount(); } catch (const exception &e) { LOGE("%{public}s", e.what()); } diff --git a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp index 6dfc45ee8..40d40c493 100644 --- a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp +++ b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp @@ -28,13 +28,13 @@ namespace DistributedFile { using namespace std; namespace { static const std::string SAME_ACCOUNT = "account"; -static const std::string ACCOUNT_LESS = "no_account"; +static const std::string ACCOUNT_LESS = "non_account"; } // namespace osAccountChangeObserver::osAccountChangeObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo) : OsAccountSubscriber(subscribeInfo) { LOGI("init first to create network of user 100"); - // lock_guard lock(serializer_); + lock_guard lock(serializer_); curUsrId = 100; AddMPInfo(curUsrId, SAME_ACCOUNT); AddMPInfo(curUsrId, ACCOUNT_LESS); diff --git a/services/distributedfiledaemon/src/network/kernel_talker.cpp b/services/distributedfiledaemon/src/network/kernel_talker.cpp index 69b46a005..46f73f23f 100644 --- a/services/distributedfiledaemon/src/network/kernel_talker.cpp +++ b/services/distributedfiledaemon/src/network/kernel_talker.cpp @@ -142,9 +142,10 @@ void KernelTalker::PollRun() return; } string ctrlPath = spt->GetMountArgument().GetCtrlPath(); + LOGI("Open node file ctrl path %{public}s", ctrlPath.c_str()); cmdFd = open(ctrlPath.c_str(), O_RDWR); if (cmdFd < 0) { - LOGE("Open node file error %{public}d", errno); + LOGE("Open node file error %{public}d, ctrl path %{public}s", errno, ctrlPath.c_str()); return; } diff --git a/utils/system/src/utils_mount_argument.cpp b/utils/system/src/utils_mount_argument.cpp index 70aefe122..9892e6a7e 100644 --- a/utils/system/src/utils_mount_argument.cpp +++ b/utils/system/src/utils_mount_argument.cpp @@ -65,6 +65,7 @@ string MountArgument::GetCtrlPath() const { auto dst = GetFullDst(); auto res = MocklispHash(dst); + stringstream ss; ss << SYSFS_HMDFS_PATH << res << "/cmd"; return ss.str(); @@ -112,9 +113,7 @@ MountArgument MountArgumentDescriptors::Alpha(int userId, string relativePath) .externalFS_ = false, .relativePath_ = relativePath, }; - if (relativePath == "account") { - mountArgument.accountless_ = false; - } else { + if (relativePath == "non_account") { mountArgument.accountless_ = true; } return mountArgument; -- Gitee From 3a75b5072fc0c7fb67e5ec01688521c03d36d3fb Mon Sep 17 00:00:00 2001 From: xianghengliang Date: Mon, 7 Feb 2022 12:23:01 +0800 Subject: [PATCH 4/5] test build failed bugfix Signed-off-by: xianghengliang --- services/distributedfiledaemon/BUILD.gn | 2 +- .../include/device/device_manager_agent.h | 5 ++- .../include/mountpoint/mount_manager.h | 9 +----- .../include/mountpoint/mount_point.h | 2 +- .../include/multiuser/os_account_observer.h | 10 +++--- .../include/network/softbus/softbus_agent.h | 1 - .../src/device/device_manager_agent.cpp | 11 +++---- .../distributedfiledaemon/src/ipc/daemon.cpp | 2 +- .../src/mountpoint/mount_manager.cpp | 1 - .../src/mountpoint/mount_point.cpp | 3 -- .../src/multiuser/os_account_observer.cpp | 24 +++++++------- test/moduletest/BUILD.gn | 2 ++ .../distributedfiledaemon_service_test.cpp | 31 ++++++++++--------- utils/system/include/utils_mount_argument.h | 9 +++--- utils/system/src/utils_mount_argument.cpp | 7 +++-- 15 files changed, 53 insertions(+), 66 deletions(-) diff --git a/services/distributedfiledaemon/BUILD.gn b/services/distributedfiledaemon/BUILD.gn index ce3d8c637..eb28773d2 100755 --- a/services/distributedfiledaemon/BUILD.gn +++ b/services/distributedfiledaemon/BUILD.gn @@ -45,9 +45,9 @@ ohos_shared_library("libdistributedfiledaemon") { external_deps = [ "dsoftbus_standard:softbus_client", "ipc:ipc_core", + "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", - "os_account_standard:os_account_innerkits", ] configs = [ "${utils_path}:compiler_configs" ] diff --git a/services/distributedfiledaemon/include/device/device_manager_agent.h b/services/distributedfiledaemon/include/device/device_manager_agent.h index d70fcec47..f777529be 100644 --- a/services/distributedfiledaemon/include/device/device_manager_agent.h +++ b/services/distributedfiledaemon/include/device/device_manager_agent.h @@ -90,9 +90,8 @@ private: std::map> mpToNetworks_; DeviceInfo localDeviceInfo_; - std::unordered_map> cidNetTypeRecord_; // cid-->same_account/accoutless's network - // key:groupId val:groupIdMark, the set of networkId - std::unordered_map>> authGroupMap_; + // cid-->same_account/accoutless's network + std::unordered_map> cidNetTypeRecord_; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/include/mountpoint/mount_manager.h b/services/distributedfiledaemon/include/mountpoint/mount_manager.h index c1509570c..7b04f10c3 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_manager.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_manager.h @@ -22,27 +22,20 @@ #include "mount_point.h" #include "utils_singleton.h" -#include "utils_log.h" namespace OHOS { namespace Storage { namespace DistributedFile { -class MountManager final : public Utils::Singleton, public std::enable_shared_from_this { +class MountManager final : public Utils::Singleton { public: - void RegisterOsAcount(); void Mount(std::unique_ptr mp); void Umount(std::weak_ptr wmp); void Umount(const std::string &groupId); DECLARE_SINGLETON(MountManager); - void RemoveMPInfoByUsrId(const int id); private: void StartInstance() override {} void StopInstance() override {} - - std::mutex serializer_; - std::vector> mountPoints_; - int curUsrId{-1}; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/include/mountpoint/mount_point.h b/services/distributedfiledaemon/include/mountpoint/mount_point.h index 6103dad3e..4c047f41c 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_point.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_point.h @@ -45,7 +45,7 @@ public: bool operator==(const MountPoint &rop) const; private: - friend class osAccountChangeObserver; + friend class OsAccountObserver; Utils::MountArgument mountArg_; void Mount() const; void Umount() const; diff --git a/services/distributedfiledaemon/include/multiuser/os_account_observer.h b/services/distributedfiledaemon/include/multiuser/os_account_observer.h index b360c57a5..a7cc9e024 100644 --- a/services/distributedfiledaemon/include/multiuser/os_account_observer.h +++ b/services/distributedfiledaemon/include/multiuser/os_account_observer.h @@ -27,11 +27,11 @@ namespace OHOS { namespace Storage { namespace DistributedFile { static constexpr int MOUNT_POINT_NUM = 2; -class osAccountChangeObserver final : public AccountSA::OsAccountSubscriber { +class OsAccountObserver final : public AccountSA::OsAccountSubscriber { public: - osAccountChangeObserver() = default; - ~osAccountChangeObserver(); - explicit osAccountChangeObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo); + OsAccountObserver() = default; + ~OsAccountObserver(); + explicit OsAccountObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo); void OnAccountsChanged(const int &id) override; private: @@ -40,7 +40,7 @@ private: std::mutex serializer_; std::unordered_map>> mountPoints_; - int curUsrId{-1}; + int curUsrId { -1 }; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/include/network/softbus/softbus_agent.h b/services/distributedfiledaemon/include/network/softbus/softbus_agent.h index ed757c315..28d88c4b7 100644 --- a/services/distributedfiledaemon/include/network/softbus/softbus_agent.h +++ b/services/distributedfiledaemon/include/network/softbus/softbus_agent.h @@ -42,7 +42,6 @@ private: std::map OpenSessionRetriedTimesMap_; std::string sessionName_; - // bool accountless_{false}; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index a9bc92959..3e3c5313f 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -152,7 +152,8 @@ std::shared_ptr DeviceManagerAgent::FindNetworkBaseTrustRe void DeviceManagerAgent::OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) { LOGI("networkId %{public}s, OnDeviceOnline begin", deviceInfo.deviceId); - // online first query this dev's trust info, 先检查 认证群组信息, 并將此cid是否是同账号信息记录到map中 + + // online first query this dev's trust info DeviceInfo info(deviceInfo); QueryRelatedGroups(info.udid_, info.cid_); @@ -163,8 +164,8 @@ void DeviceManagerAgent::OnDeviceOnline(const DistributedHardware::DmDeviceInfo LOGE("cid %{public}s network is null!", info.cid_.c_str()); return; } - auto cmd = make_unique>( - &NetworkAgentTemplate::ConnectDeviceAsync, info); + auto cmd = + make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption({ .tryTimes_ = MAX_RETRY_COUNT, }); @@ -184,11 +185,10 @@ void DeviceManagerAgent::OnDeviceOffline(const DistributedHardware::DmDeviceInfo LOGE("cid %{public}s network is null!", info.cid_.c_str()); return; } + auto cmd = make_unique>(&NetworkAgentTemplate::DisconnectDevice, info); networkAgent->Recv(move(cmd)); cidNetTypeRecord_.erase(info.cid_); - - // AuthGroupOfflineProc(info); LOGI("OnDeviceOffline end"); } @@ -297,7 +297,6 @@ void DeviceManagerAgent::OnRemoteDied() StartInstance(); ReconnectOnlineDevices(); } - DeviceInfo &DeviceManagerAgent::GetLocalDeviceInfo() { return localDeviceInfo_; diff --git a/services/distributedfiledaemon/src/ipc/daemon.cpp b/services/distributedfiledaemon/src/ipc/daemon.cpp index 8bc6120ae..f50c2d570 100644 --- a/services/distributedfiledaemon/src/ipc/daemon.cpp +++ b/services/distributedfiledaemon/src/ipc/daemon.cpp @@ -47,7 +47,7 @@ void Daemon::RegisterOsAccount() osAccountSubscribeInfo.SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED); osAccountSubscribeInfo.SetName("distributed_file_service"); - auto subScriber = std::make_shared(osAccountSubscribeInfo); + auto subScriber = std::make_shared(osAccountSubscribeInfo); int ret = OHOS::AccountSA::OsAccountManager::SubscribeOsAccount(subScriber); if (ret != 0) { LOGE("register os account fail ret %{public}d", ret); diff --git a/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp index 0dc7bccdd..3f8696eaa 100644 --- a/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp +++ b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp @@ -29,7 +29,6 @@ using namespace std; MountManager::MountManager() { - } MountManager::~MountManager() diff --git a/services/distributedfiledaemon/src/mountpoint/mount_point.cpp b/services/distributedfiledaemon/src/mountpoint/mount_point.cpp index a6a9c1d57..8479cf703 100644 --- a/services/distributedfiledaemon/src/mountpoint/mount_point.cpp +++ b/services/distributedfiledaemon/src/mountpoint/mount_point.cpp @@ -15,9 +15,6 @@ #include "mountpoint/mount_point.h" -#include -#include - #include "utils_directory.h" #include "utils_log.h" diff --git a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp index 40d40c493..086f7a27e 100644 --- a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp +++ b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp @@ -15,9 +15,6 @@ #include "multiuser/os_account_observer.h" -#include -#include - #include "device/device_manager_agent.h" #include "utils_log.h" #include "utils_mount_argument.h" @@ -29,24 +26,25 @@ using namespace std; namespace { static const std::string SAME_ACCOUNT = "account"; static const std::string ACCOUNT_LESS = "non_account"; +static constexpr int DEFAULT_ACCOUNT = 100; } // namespace -osAccountChangeObserver::osAccountChangeObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo) : OsAccountSubscriber(subscribeInfo) +OsAccountObserver::OsAccountObserver(const AccountSA::OsAccountSubscribeInfo &subscribeInfo) + : OsAccountSubscriber(subscribeInfo) { - LOGI("init first to create network of user 100"); + LOGI("init first to create network of default user"); lock_guard lock(serializer_); - curUsrId = 100; + curUsrId = DEFAULT_ACCOUNT; AddMPInfo(curUsrId, SAME_ACCOUNT); AddMPInfo(curUsrId, ACCOUNT_LESS); - LOGI("init first to create network of user 100, done"); + LOGI("init first to create network of user %{public}d, done", DEFAULT_ACCOUNT); } -osAccountChangeObserver::~osAccountChangeObserver() +OsAccountObserver::~OsAccountObserver() { - // OHOS::AccountSA::OsAccountManager::UnsubscribeOsAccount(shared_from_this()); } -void osAccountChangeObserver::AddMPInfo(const int id, const std::string &relativePath) +void OsAccountObserver::AddMPInfo(const int id, const std::string &relativePath) { auto smp = make_shared(Utils::MountArgumentDescriptors::Alpha(id, relativePath)); auto dm = DeviceManagerAgent::GetInstance(); @@ -54,11 +52,11 @@ void osAccountChangeObserver::AddMPInfo(const int id, const std::string &relativ mountPoints_[id].emplace_back(smp); } -void osAccountChangeObserver::OnAccountsChanged(const int &id) +void OsAccountObserver::OnAccountsChanged(const int &id) { LOGI("user id changed to %{public}d", id); lock_guard lock(serializer_); - if (curUsrId != -1) { // todo: 仅仅是切断当前用户,是否需要删除之前的用户信息? + if (curUsrId != -1) { // first stop curUsrId network RemoveMPInfo(curUsrId); } @@ -70,7 +68,7 @@ void osAccountChangeObserver::OnAccountsChanged(const int &id) LOGI("user id %{public}d, add network done", curUsrId); } -void osAccountChangeObserver::RemoveMPInfo(const int id) +void OsAccountObserver::RemoveMPInfo(const int id) { auto iter = mountPoints_.find(id); if (iter == mountPoints_.end()) { diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index 8bc51b452..0d88bc1e0 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -39,6 +39,7 @@ ohos_moduletest("DistributedFileDaemonServiceTest") { "${services_path}/distributedfiledaemon/src/ipc/daemon_stub.cpp", "${services_path}/distributedfiledaemon/src/mountpoint/mount_manager.cpp", "${services_path}/distributedfiledaemon/src/mountpoint/mount_point.cpp", + "${services_path}/distributedfiledaemon/src/multiuser/os_account_observer.cpp", "${services_path}/distributedfiledaemon/src/network/kernel_talker.cpp", "${services_path}/distributedfiledaemon/src/network/network_agent_template.cpp", "${services_path}/distributedfiledaemon/src/network/session_pool.cpp", @@ -68,6 +69,7 @@ ohos_moduletest("DistributedFileDaemonServiceTest") { external_deps = [ "dsoftbus_standard:softbus_client", "ipc:ipc_core", + "os_account_standard:os_account_innerkits", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/test/moduletest/src/distributedfiledaemon_service_test.cpp b/test/moduletest/src/distributedfiledaemon_service_test.cpp index 9f29c2907..fb2201e2d 100644 --- a/test/moduletest/src/distributedfiledaemon_service_test.cpp +++ b/test/moduletest/src/distributedfiledaemon_service_test.cpp @@ -39,9 +39,10 @@ namespace Test { using namespace testing::ext; using namespace std; -static const string srcHead = "/data/misc_ce/"; +static const string srcHead = "/data/service/el2/"; static const string dstHead = "/mnt/hmdfs/"; -static const string cacheHead = "/data/misc_ce/"; +static const string cacheHead = "/data/service/el2/"; +static const string SAME_ACCOUNT = "account"; std::mutex cmdMutex_; const int KEY_MAX_LEN = 32; @@ -96,7 +97,7 @@ void DistributedFileDaemonServiceTest::TearDown(void) HWTEST_F(DistributedFileDaemonServiceTest, mount_umount_test_001, TestSize.Level1) { auto mp = make_unique( - OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(9527)); + OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(100, SAME_ACCOUNT)); shared_ptr smp = move(mp); @@ -119,9 +120,9 @@ HWTEST_F(DistributedFileDaemonServiceTest, mount_umount_test_001, TestSize.Level */ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_001_mount, TestSize.Level1) { - const int userId = 3333; + const int userId = 101; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId); + auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -193,7 +194,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 const int len = sizeof(userId) / sizeof(userId[0]); for (int i = 0; i < len; i++) { - mountArgument[i] = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId[i]); + mountArgument[i] = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId[i], SAME_ACCOUNT); auto mp = make_unique(mountArgument[i]); smpArr[i] = move(mp); } @@ -265,7 +266,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 { const int userId = 3337; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId); + auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -330,7 +331,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 { const int userId = 3338; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId); + auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -399,7 +400,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 { const int userId = 3339; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId); + auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -501,7 +502,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, TestSize.Level1) { const int userId = 4200; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId); + auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -532,7 +533,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, TestSize.Level1) { const int userId = 4201; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId); + auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -575,8 +576,8 @@ HWTEST_F(DistributedFileDaemonServiceTest, { const int userId1 = 4202; const int userId2 = 4203; - auto mountArgument1 = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId1); - auto mountArgument2 = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId2); + auto mountArgument1 = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId1, SAME_ACCOUNT); + auto mountArgument2 = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId2, SAME_ACCOUNT); auto mp1 = make_unique(mountArgument1); auto mp2 = make_unique(mountArgument2); shared_ptr smp1 = move(mp1); @@ -613,7 +614,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, TestSize.Level1) { const int userId = 4204; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId); + auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -654,7 +655,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_015_kernel_notify_deal, TestSize.Level1) { const int userId = 4500; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId); + auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); diff --git a/utils/system/include/utils_mount_argument.h b/utils/system/include/utils_mount_argument.h index 10ad193aa..6e5b0e32f 100644 --- a/utils/system/include/utils_mount_argument.h +++ b/utils/system/include/utils_mount_argument.h @@ -23,15 +23,15 @@ namespace Storage { namespace DistributedFile { namespace Utils { struct MountArgument final { - int userId_{0}; + int userId_ { 0 }; bool accountless_{false}; bool needInitDir_{false}; bool useCache_{false}; bool caseSensitive_{false}; bool enableMergeView_{false}; - bool enableFixupOwnerShip_{false}; - bool enableOfflineStash_{true}; - bool externalFS_{false}; + bool enableFixupOwnerShip_ { false }; + bool enableOfflineStash_ { true }; + bool externalFS_ { false }; std::string relativePath_; std::string GetFullSrc() const; @@ -51,4 +51,3 @@ public: } // namespace Storage } // namespace OHOS #endif // UTILS_MOUNT_ARGUMENT_H - diff --git a/utils/system/src/utils_mount_argument.cpp b/utils/system/src/utils_mount_argument.cpp index 9892e6a7e..17ac0d3c4 100644 --- a/utils/system/src/utils_mount_argument.cpp +++ b/utils/system/src/utils_mount_argument.cpp @@ -39,7 +39,7 @@ string MountArgument::GetFullSrc() const string MountArgument::GetFullDst() const { stringstream ss; - ss << BASE_MOUNT_POINT << userId_ << "/" << relativePath_; + ss << BASE_MOUNT_POINT << userId_ << "/" << relativePath_; return ss.str(); } @@ -113,12 +113,13 @@ MountArgument MountArgumentDescriptors::Alpha(int userId, string relativePath) .externalFS_ = false, .relativePath_ = relativePath, }; + if (relativePath == "non_account") { mountArgument.accountless_ = true; } return mountArgument; -} +}; } // namespace Utils } // namespace DistributedFile } // namespace Storage -} // namespace OHOS +} // namespace OHOS \ No newline at end of file -- Gitee From 5e9c4144e2fb2433d9038533e58ae40acf14c313 Mon Sep 17 00:00:00 2001 From: xianghengliang Date: Mon, 7 Feb 2022 14:29:26 +0800 Subject: [PATCH 5/5] code static check fix Signed-off-by: xianghengliang --- .../src/device/device_manager_agent.cpp | 6 +++--- .../src/distributedfiledaemon_service_test.cpp | 2 +- utils/system/include/utils_mount_argument.h | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index 3e3c5313f..23689c6c1 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -84,7 +84,7 @@ void DeviceManagerAgent::JoinGroup(weak_ptr mp) { unique_lock lock(mpToNetworksMutex_); agent = make_shared(mp); - auto [ignored, inserted] = mpToNetworks_.insert({smp->GetID(), agent}); + auto [ignored, inserted] = mpToNetworks_.insert({ smp->GetID(), agent }); if (!inserted) { stringstream ss; ss << "Failed to join group: Mountpoint existed" << smp->ToString(); @@ -257,9 +257,9 @@ void DeviceManagerAgent::QueryRelatedGroups(const std::string &udid, const std:: unique_lock lock(mpToNetworksMutex_); for (const auto &group : groupList) { if (CheckIsAuthGroup(group)) { - cidNetTypeRecord_.insert({networkId, FindNetworkBaseTrustRelation(true)}); // accountless == true + cidNetTypeRecord_.insert({ networkId, FindNetworkBaseTrustRelation(true) }); } else { - cidNetTypeRecord_.insert({networkId, FindNetworkBaseTrustRelation(false)}); + cidNetTypeRecord_.insert({ networkId, FindNetworkBaseTrustRelation(false) }); } } diff --git a/test/moduletest/src/distributedfiledaemon_service_test.cpp b/test/moduletest/src/distributedfiledaemon_service_test.cpp index fb2201e2d..38199d5d3 100644 --- a/test/moduletest/src/distributedfiledaemon_service_test.cpp +++ b/test/moduletest/src/distributedfiledaemon_service_test.cpp @@ -194,7 +194,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 const int len = sizeof(userId) / sizeof(userId[0]); for (int i = 0; i < len; i++) { - mountArgument[i] = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId[i], SAME_ACCOUNT); + mountArgument[i] = Utils::MountArgumentDescriptors::Alpha(userId[i], SAME_ACCOUNT); auto mp = make_unique(mountArgument[i]); smpArr[i] = move(mp); } diff --git a/utils/system/include/utils_mount_argument.h b/utils/system/include/utils_mount_argument.h index 6e5b0e32f..e3cf81f15 100644 --- a/utils/system/include/utils_mount_argument.h +++ b/utils/system/include/utils_mount_argument.h @@ -24,11 +24,11 @@ namespace DistributedFile { namespace Utils { struct MountArgument final { int userId_ { 0 }; - bool accountless_{false}; - bool needInitDir_{false}; - bool useCache_{false}; - bool caseSensitive_{false}; - bool enableMergeView_{false}; + bool accountless_ { false }; + bool needInitDir_ { false }; + bool useCache_ { false }; + bool caseSensitive_ { false }; + bool enableMergeView_ { false }; bool enableFixupOwnerShip_ { false }; bool enableOfflineStash_ { true }; bool externalFS_ { false }; -- Gitee