From a3056c556c8468bd5fe82a7aaa3829b501aa60b1 Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Mon, 2 Dec 2024 11:29:20 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- .../common/include/storage_service_errno.h | 9 ++++ .../storage_daemon/user/src/mount_manager.cpp | 54 +++++++++---------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/services/common/include/storage_service_errno.h b/services/common/include/storage_service_errno.h index 9a7dc621..283c79a1 100644 --- a/services/common/include/storage_service_errno.h +++ b/services/common/include/storage_service_errno.h @@ -79,6 +79,15 @@ enum ErrNo { E_ELX_KEY_INACTIVE_ERROR, E_STORAGE_USAGE_NOT_ENOUGH = 250, + + // only for use mount and unmount + E_CLOUD_NOT_READY = 300, + E_UMOUNT_CLOUD_FUSE = 301, + E_UMOUNT_CLOUD = 302, + E_UMOUNT_MEDIA_FUSE = 303, + E_UMOUNT_SHAREFS = 304, + E_UMOUNT_HMFS = 305, + E_UMOUNT_HMDFS = 306, }; enum JsErrCode { diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index e82ed99a..bc9dd240 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -831,7 +831,7 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list &moun LOGI("unmount sharefs path start, total %{public}d.", total); res = UMountByList(list, mountFailList); if (res != E_OK) { - result = res; + result = E_UMOUNT_SHAREFS; } list = mountMap[MOUNT_POINT_TYPE_HMFS]; @@ -839,7 +839,7 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list &moun LOGI("unmount hmfs path start, total %{public}d.", total); res = UMountByList(list, mountFailList); if (res != E_OK) { - result = res; + result = E_UMOUNT_HMFS; } UmountMntUserTmpfs(userId); @@ -848,7 +848,7 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list &moun LOGI("unmount hmdfs path start, total %{public}d.", total); res = UMountByList(list, mountFailList); if (res != E_OK) { - result = res; + result = E_UMOUNT_HMDFS; } if (result != E_OK) { @@ -873,7 +873,7 @@ int32_t MountManager::UMountByList(std::list &list, std::list Date: Mon, 2 Dec 2024 16:24:20 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index bc9dd240..a65010fa 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -948,13 +948,13 @@ int32_t MountManager::CloudUMount(int32_t userId) err = UMount2(cloudFusePath, MNT_DETACH); if (err != E_OK && errno != ENOENT && errno != EINVAL) { LOGE("cloud fuse umount failed, errno is %{public}d.", errno); - return E_CLOUD_FUSE_UMOUNT; + return E_UMOUNT_CLOUD_FUSE; } const string cloudPath = cloudMntArgs.GetFullMediaCloud(); err = UMount2(cloudPath, MNT_DETACH); if (err != E_OK && errno != ENOENT && errno != EINVAL) { LOGE("cloud umount failed, errno %{public}d", errno); - return E_CLOUD_UMOUNT; + return E_UMOUNT_CLOUD; } LOGI("cloud umount success"); return E_OK; @@ -1597,7 +1597,7 @@ int32_t MountManager::UMountMediaFuse(int32_t userId) err = UMount2(path, MNT_DETACH); if (err != E_OK && errno != ENOENT && errno != EINVAL) { LOGE("media fuse umount failed, errno %{public}d", errno); - return E_MEDIA_FUSE_UMOUNT; + return E_UMOUNT_MEDIA_FUSE; } LOGI("umount media fuse success"); return E_OK; -- Gitee From a0372d275f53a94e3324b3e8cdc039883275246e Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Tue, 3 Dec 2024 09:20:36 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index a65010fa..6f01d84d 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -1539,12 +1539,12 @@ int32_t MountManager::UmountMntUserTmpfs(int32_t userId) Utils::MountArgument mountArgument(Utils::MountArgumentDescriptors::Alpha(userId, "")); std::string path = mountArgument.GetSharefsDocCurPath() + "/appdata"; int32_t res = UMount2(path, MNT_DETACH); - if (res != E_OK) { + if (res != E_OK && errno != ENOENT && errno != EINVAL) { LOGE("failed to umount with detach, path %{public}s, errno %{public}d.", path.c_str(), errno); } path = mountArgument.GetCurOtherAppdataPath(); res = UMount2(path, MNT_DETACH); - if (res != E_OK) { + if (res != E_OK && errno != ENOENT && errno != EINVAL) { LOGE("failed to umount with detach, path %{public}s, errno %{public}d.", path.c_str(), errno); } return E_OK; -- Gitee From 551fb5bf73520952b35cb05a40597d70a22e875c Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Tue, 3 Dec 2024 12:35:36 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index 6f01d84d..1dd7f479 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -64,6 +64,7 @@ const string PACKAGE_NAME_FLAG = ""; const string MOUNT_POINT_INFO = "/proc/mounts"; const string MOUNT_POINT_TYPE_HMDFS = "hmdfs"; const string MOUNT_POINT_TYPE_HMFS = "hmfs"; +const string MOUNT_POINT_TYPE_F2FS = "f2fs"; const string MOUNT_POINT_TYPE_SHAREFS = "sharefs"; const string EL2_BASE = "/data/storage/el2/base/"; const string MOUNT_SUFFIX = "_locked"; @@ -774,7 +775,7 @@ void MountManager::MountPointToList(std::list &hmdfsList, std::list } return; } - if (type == MOUNT_POINT_TYPE_HMFS) { + if (type == MOUNT_POINT_TYPE_HMFS || type == MOUNT_POINT_TYPE_F2FS) { if (dst.length() >= hmfsPrefix.length() && dst.substr(0, hmfsPrefix.length()) == hmfsPrefix) { hmfsList.push_front(dst); } -- Gitee From 0aa450641656beed6d21e39c95fb5250c7fe21a5 Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 6 Dec 2024 10:57:10 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- .../common/include/storage_service_errno.h | 3 + .../include/user/mount_manager.h | 2 +- .../storage_daemon/user/src/mount_manager.cpp | 110 +++++++----------- 3 files changed, 47 insertions(+), 68 deletions(-) diff --git a/services/common/include/storage_service_errno.h b/services/common/include/storage_service_errno.h index 283c79a1..f983fbb5 100644 --- a/services/common/include/storage_service_errno.h +++ b/services/common/include/storage_service_errno.h @@ -88,6 +88,9 @@ enum ErrNo { E_UMOUNT_SHAREFS = 304, E_UMOUNT_HMFS = 305, E_UMOUNT_HMDFS = 306, + E_UMOUNT_LOCAL = 307, + E_UMOUNT_ALL = 308, + E_UMOUNT_PROC_OPEN = 309, }; enum JsErrCode { diff --git a/services/storage_daemon/include/user/mount_manager.h b/services/storage_daemon/include/user/mount_manager.h index d2b71311..939556d8 100644 --- a/services/storage_daemon/include/user/mount_manager.h +++ b/services/storage_daemon/include/user/mount_manager.h @@ -117,7 +117,6 @@ private: int32_t HmdfsMount(int32_t userId); int32_t HmdfsMount(int32_t userId, std::string relativePath, bool mountCloudDisk = false); int32_t HmdfsTwiceMount(int32_t userId, const std::string &relativePath); - int32_t HmdfsUMount(int32_t userId, std::string relativePath); int32_t SharefsMount(int32_t userId); int32_t HmSharefsMount(int32_t userId, std::string &srcPath, std::string &dstPath); int32_t LocalMount(int32_t userId); @@ -138,6 +137,7 @@ private: int32_t SharedMount(const std::string &path); int32_t BindAndRecMount(std::string &srcPath, std::string &dstPath, bool isUseSlave = true); int32_t UmountMntUserTmpfs(int32_t userId); + int32_t UMountWithDetachByList(std::list &mountPoints); DISALLOW_COPY_AND_MOVE(MountManager); diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index 1dd7f479..e44de29e 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -800,7 +800,7 @@ int32_t MountManager::FindMountPointsToMap(std::map hmdfsList; std::list hmfsList; @@ -826,12 +826,13 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list &moun if (res != E_OK) { return res; } - int32_t result = 0; + int32_t result = E_OK; std::list list = mountMap[MOUNT_POINT_TYPE_SHAREFS]; int total = static_cast(list.size()); LOGI("unmount sharefs path start, total %{public}d.", total); res = UMountByList(list, mountFailList); if (res != E_OK) { + LOGE("failed to umount sharefs mount point, res is %{public}d", res); result = E_UMOUNT_SHAREFS; } @@ -840,6 +841,7 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list &moun LOGI("unmount hmfs path start, total %{public}d.", total); res = UMountByList(list, mountFailList); if (res != E_OK) { + LOGE("failed to umount hmfs mount point, res is %{public}d", res); result = E_UMOUNT_HMFS; } UmountMntUserTmpfs(userId); @@ -849,20 +851,11 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list &moun LOGI("unmount hmdfs path start, total %{public}d.", total); res = UMountByList(list, mountFailList); if (res != E_OK) { + LOGE("failed to umount hmdfs mount point, res is %{public}d", res); result = E_UMOUNT_HMDFS; } - - if (result != E_OK) { - for (const auto &item: mountFailList) { - res = UMount2(item.c_str(), MNT_DETACH); - if (res != E_OK) { - LOGE("failed to unmount with detach, path %{public}s, errno %{public}d.", item.c_str(), errno); - } - } - return result; - } - LOGI("UMountAllPath success"); - return E_OK; + LOGI("UMountAllPath end"); + return result; } int32_t MountManager::UMountByList(std::list &list, std::list &mountFailList) @@ -880,7 +873,6 @@ int32_t MountManager::UMountByList(std::list &list, std::list mountFailList; + int32_t uMountAllPathRes = UMountAllPath(userId, mountFailList); + if (uMountAllPathRes != E_OK) { + FindAndKillProcess(userId, mountFailList); + if (uMountAllPathRes == E_UMOUNT_PROC_OPEN) { + res = uMountAllPathRes; } - } else { - std::list mountFailList; - err = UMountAllPath(userId, mountFailList); - if (err != E_OK) { - LOGE("failed to umount hmdfs mount point, err is %{public}d", err); - FindAndKillProcess(userId, mountFailList); + if (UMountWithDetachByList(mountFailList) != E_OK) { + res = uMountAllPathRes; } } - LOGI("umount cloud mount point start."); - int32_t count = 0; - while (count < UMOUNT_RETRY_TIMES) { - err = CloudUMount(userId); - if (err == E_OK) { - break; - } else if (errno == EBUSY) { - count++; - continue; - } - LOGE("failed to umount cloud mount point, err %{public}d", err); - return err; - } - - LOGI("umount media fuse mount point start."); - count = 0; - while (count < UMOUNT_RETRY_TIMES) { - err = UMountMediaFuse(userId); - if (err == E_OK) { - break; - } else if (errno == EBUSY) { - count++; - continue; + int32_t cloudUnMountRes = CloudUMount(userId); + if (cloudUnMountRes != E_OK) { + res = cloudUnMountRes; + } + UMountMediaFuse(userId); + return res; +} + +int32_t MountManager::UMountWithDetachByList(std::list &mountPoints) +{ + if (mountPoints.empty()) { + return E_OK; + } + int32_t res = E_OK; + for (const auto &item: mountPoints) { + LOGE("umount path with detach: %{public}s.", item.c_str()); + int32_t umountRes = UMount2(item.c_str(), MNT_DETACH); + if (umountRes != E_OK && errno != ENOENT && errno != EINVAL) { + LOGE("failed to unmount with detach, path %{public}s, errno %{public}d.", item.c_str(), errno); + res = umountRes; } - LOGE("failed to umount media fuse mount point, err %{public}d", err); - return err; } - return E_OK; + return res; } int32_t MountManager::PrepareHmdfsDirs(int32_t userId) -- Gitee From 94538a4945098cb6408d78745abb521a22eda4ab Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 6 Dec 2024 10:58:07 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index e44de29e..12ea17f2 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -1097,7 +1097,7 @@ int32_t MountManager::UmountByUser(int32_t userId) if (!SupportHmdfs() && LocalUMount(userId) != E_OK) { return E_UMOUNT_LOCAL; } - LOGI("umount all path start."); + LOGI("umount all path start"); int32_t res = E_OK; std::list mountFailList; int32_t uMountAllPathRes = UMountAllPath(userId, mountFailList); @@ -1110,7 +1110,7 @@ int32_t MountManager::UmountByUser(int32_t userId) res = uMountAllPathRes; } } - LOGI("umount cloud mount point start."); + LOGI("umount cloud mount point start"); int32_t cloudUnMountRes = CloudUMount(userId); if (cloudUnMountRes != E_OK) { res = cloudUnMountRes; -- Gitee From 7eb925b5ba73787f50382da0f168fe052ed61f4a Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 6 Dec 2024 10:58:26 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index 12ea17f2..e44de29e 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -1097,7 +1097,7 @@ int32_t MountManager::UmountByUser(int32_t userId) if (!SupportHmdfs() && LocalUMount(userId) != E_OK) { return E_UMOUNT_LOCAL; } - LOGI("umount all path start"); + LOGI("umount all path start."); int32_t res = E_OK; std::list mountFailList; int32_t uMountAllPathRes = UMountAllPath(userId, mountFailList); @@ -1110,7 +1110,7 @@ int32_t MountManager::UmountByUser(int32_t userId) res = uMountAllPathRes; } } - LOGI("umount cloud mount point start"); + LOGI("umount cloud mount point start."); int32_t cloudUnMountRes = CloudUMount(userId); if (cloudUnMountRes != E_OK) { res = cloudUnMountRes; -- Gitee From ab84d9291976ac5f6e96382761c7b097783f6cdd Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 6 Dec 2024 10:59:02 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index e44de29e..12ea17f2 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -1097,7 +1097,7 @@ int32_t MountManager::UmountByUser(int32_t userId) if (!SupportHmdfs() && LocalUMount(userId) != E_OK) { return E_UMOUNT_LOCAL; } - LOGI("umount all path start."); + LOGI("umount all path start"); int32_t res = E_OK; std::list mountFailList; int32_t uMountAllPathRes = UMountAllPath(userId, mountFailList); @@ -1110,7 +1110,7 @@ int32_t MountManager::UmountByUser(int32_t userId) res = uMountAllPathRes; } } - LOGI("umount cloud mount point start."); + LOGI("umount cloud mount point start"); int32_t cloudUnMountRes = CloudUMount(userId); if (cloudUnMountRes != E_OK) { res = cloudUnMountRes; -- Gitee From 182a50c829b62e2649141a16499b8dc7ba223e02 Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 6 Dec 2024 10:59:27 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index 12ea17f2..e44de29e 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -1097,7 +1097,7 @@ int32_t MountManager::UmountByUser(int32_t userId) if (!SupportHmdfs() && LocalUMount(userId) != E_OK) { return E_UMOUNT_LOCAL; } - LOGI("umount all path start"); + LOGI("umount all path start."); int32_t res = E_OK; std::list mountFailList; int32_t uMountAllPathRes = UMountAllPath(userId, mountFailList); @@ -1110,7 +1110,7 @@ int32_t MountManager::UmountByUser(int32_t userId) res = uMountAllPathRes; } } - LOGI("umount cloud mount point start"); + LOGI("umount cloud mount point start."); int32_t cloudUnMountRes = CloudUMount(userId); if (cloudUnMountRes != E_OK) { res = cloudUnMountRes; -- Gitee From 8cbe939755dc82203aa92e4d8d00f83736b1e1fb Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 13 Dec 2024 10:09:24 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- .../common/include/storage_service_errno.h | 18 +++--- .../storage_daemon/user/src/mount_manager.cpp | 60 +++++++++---------- 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/services/common/include/storage_service_errno.h b/services/common/include/storage_service_errno.h index f983fbb5..e5993ef5 100644 --- a/services/common/include/storage_service_errno.h +++ b/services/common/include/storage_service_errno.h @@ -81,16 +81,14 @@ enum ErrNo { E_STORAGE_USAGE_NOT_ENOUGH = 250, // only for use mount and unmount - E_CLOUD_NOT_READY = 300, - E_UMOUNT_CLOUD_FUSE = 301, - E_UMOUNT_CLOUD = 302, - E_UMOUNT_MEDIA_FUSE = 303, - E_UMOUNT_SHAREFS = 304, - E_UMOUNT_HMFS = 305, - E_UMOUNT_HMDFS = 306, - E_UMOUNT_LOCAL = 307, - E_UMOUNT_ALL = 308, - E_UMOUNT_PROC_OPEN = 309, + E_UMOUNT_CLOUD_FUSE = 300, + E_UMOUNT_CLOUD = 301, + E_UMOUNT_MEDIA_FUSE = 302, + E_UMOUNT_SHAREFS = 303, + E_UMOUNT_HMFS = 304, + E_UMOUNT_HMDFS = 305, + E_UMOUNT_LOCAL = 306, + E_UMOUNT_PROC_OPEN = 307, }; enum JsErrCode { diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index e44de29e..7afc1cde 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -53,7 +53,6 @@ using namespace std; using namespace OHOS::FileManagement::CloudFile; #endif using namespace OHOS::StorageService; -constexpr int32_t UMOUNT_RETRY_TIMES = 3; constexpr int32_t ONE_KB = 1024; constexpr int32_t DEFAULT_USERID = 100; std::shared_ptr MountManager::instance_ = nullptr; @@ -854,7 +853,7 @@ int32_t MountManager::UMountAllPath(int32_t userId, std::list &moun LOGE("failed to umount hmdfs mount point, res is %{public}d", res); result = E_UMOUNT_HMDFS; } - LOGI("UMountAllPath end"); + LOGI("UMountAllPath end, res is %{public}d", result); return result; } @@ -918,10 +917,6 @@ void MountManager::SetCloudState(bool active) int32_t MountManager::CloudUMount(int32_t userId) { - if (!cloudReady_) { - LOGE("cloud service not ready."); - return E_CLOUD_NOT_READY; - } #ifdef DFS_SERVICE int32_t err = E_OK; Utils::MountArgument cloudMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, "")); @@ -1078,44 +1073,43 @@ void MountManager::PrepareFileManagerDir(int32_t userId) int32_t MountManager::LocalUMount(int32_t userId) { + int res = E_OK; Utils::MountArgument LocalMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, "account")); - int err = UMount(LocalMntArgs.GetCommFullPath() + "local/"); - if (err != E_OK && errno != ENOENT && errno != EINVAL) { - LOGE("failed to un bind mount, errno %{public}d, ComDataDir dst %{public}s", errno, - LocalMntArgs.GetCommFullPath().c_str()); + std::string path = LocalMntArgs.GetCommFullPath() + "local/"; + int unMountRes = UMount(path); + if (unMountRes != E_OK && errno != ENOENT && errno != EINVAL) { + LOGE("failed to unmount local, errno %{public}d, path is %{public}s", errno, path.c_str()); + res = unMountRes; + } + path = LocalMntArgs.GetCloudFullPath(); + unMountRes = UMount(path); + if (unMountRes != E_OK && errno != ENOENT && errno != EINVAL) { + LOGE("failed to unmount local, errno %{public}d, path is %{public}s", errno, path.c_str()); + res = unMountRes; } - err = UMount(LocalMntArgs.GetCloudFullPath()); - if (err != E_OK && errno != ENOENT && errno != EINVAL) { - LOGE("failed to un bind mount, errno %{public}d, CloudDataDir dst %{public}s", errno, - LocalMntArgs.GetCloudFullPath().c_str()); - } - return err; + return res; } int32_t MountManager::UmountByUser(int32_t userId) { - if (!SupportHmdfs() && LocalUMount(userId) != E_OK) { - return E_UMOUNT_LOCAL; - } - LOGI("umount all path start."); int32_t res = E_OK; - std::list mountFailList; - int32_t uMountAllPathRes = UMountAllPath(userId, mountFailList); - if (uMountAllPathRes != E_OK) { - FindAndKillProcess(userId, mountFailList); - if (uMountAllPathRes == E_UMOUNT_PROC_OPEN) { - res = uMountAllPathRes; - } - if (UMountWithDetachByList(mountFailList) != E_OK) { - res = uMountAllPathRes; + if (!SupportHmdfs() && LocalUMount(userId) != E_OK) { + res = E_UMOUNT_LOCAL; + } else { + LOGI("umount all path start."); + std::list mountFailList; + int32_t unMountRes = UMountAllPath(userId, mountFailList); + if (unMountRes != E_OK && unMountRes != E_UMOUNT_PROC_OPEN) { + FindAndKillProcess(userId, mountFailList); + std::list tempList; + res = UMountByList(mountFailList, tempList); } } + LOGI("umount cloud mount point start."); - int32_t cloudUnMountRes = CloudUMount(userId); - if (cloudUnMountRes != E_OK) { - res = cloudUnMountRes; - } + res = CloudUMount(userId); UMountMediaFuse(userId); + LOGI("unmount end, res is %{public}d.", res); return res; } -- Gitee From 4ad92ddf4c6577923c52248487f3822d0a91a226 Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 13 Dec 2024 10:10:55 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- .../storage_daemon/include/user/mount_manager.h | 1 - .../storage_daemon/user/src/mount_manager.cpp | 17 ----------------- 2 files changed, 18 deletions(-) diff --git a/services/storage_daemon/include/user/mount_manager.h b/services/storage_daemon/include/user/mount_manager.h index 939556d8..3f1565a9 100644 --- a/services/storage_daemon/include/user/mount_manager.h +++ b/services/storage_daemon/include/user/mount_manager.h @@ -137,7 +137,6 @@ private: int32_t SharedMount(const std::string &path); int32_t BindAndRecMount(std::string &srcPath, std::string &dstPath, bool isUseSlave = true); int32_t UmountMntUserTmpfs(int32_t userId); - int32_t UMountWithDetachByList(std::list &mountPoints); DISALLOW_COPY_AND_MOVE(MountManager); diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index 7afc1cde..f8371944 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -1113,23 +1113,6 @@ int32_t MountManager::UmountByUser(int32_t userId) return res; } -int32_t MountManager::UMountWithDetachByList(std::list &mountPoints) -{ - if (mountPoints.empty()) { - return E_OK; - } - int32_t res = E_OK; - for (const auto &item: mountPoints) { - LOGE("umount path with detach: %{public}s.", item.c_str()); - int32_t umountRes = UMount2(item.c_str(), MNT_DETACH); - if (umountRes != E_OK && errno != ENOENT && errno != EINVAL) { - LOGE("failed to unmount with detach, path %{public}s, errno %{public}d.", item.c_str(), errno); - res = umountRes; - } - } - return res; -} - int32_t MountManager::PrepareHmdfsDirs(int32_t userId) { for (const DirInfo &dir : hmdfsDirVec_) { -- Gitee From 4fdb7846cb10f3c9b7ab4f59701795eb5180a000 Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 13 Dec 2024 12:42:57 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index f8371944..6f455dd5 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -1102,12 +1102,17 @@ int32_t MountManager::UmountByUser(int32_t userId) if (unMountRes != E_OK && unMountRes != E_UMOUNT_PROC_OPEN) { FindAndKillProcess(userId, mountFailList); std::list tempList; - res = UMountByList(mountFailList, tempList); + if (UMountByList(mountFailList, tempList) != E_OK) { + res = unMountRes; + } } } LOGI("umount cloud mount point start."); - res = CloudUMount(userId); + int32_t cloudUMount = CloudUMount(userId); + if (cloudUMount != E_OK) { + res = cloudUMount; + } UMountMediaFuse(userId); LOGI("unmount end, res is %{public}d.", res); return res; -- Gitee From ff3c83d342b9518595019e4dc2ef65ebe57813e8 Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 13 Dec 2024 14:37:20 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/src/mount_manager.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/services/storage_daemon/user/src/mount_manager.cpp b/services/storage_daemon/user/src/mount_manager.cpp index 6f455dd5..03437fb1 100644 --- a/services/storage_daemon/user/src/mount_manager.cpp +++ b/services/storage_daemon/user/src/mount_manager.cpp @@ -1512,21 +1512,15 @@ int32_t MountManager::UmountMntUserTmpfs(int32_t userId) int32_t MountManager::MountMediaFuse(int32_t userId, int32_t &devFd) { LOGI("start mount media fuse"); - - // umount mountpoint first + UMountMediaFuse(userId); Utils::MountArgument mediaMntArgs(Utils::MountArgumentDescriptors::Alpha(userId, "")); const string path = mediaMntArgs.GetFullMediaFuse(); - if (E_OK != UMount2(path.c_str(), MNT_DETACH)) { - LOGE("UMount media fuse mount point failed, errno = %{public}d", errno); - } - // open fuse devFd = open("/dev/fuse", O_RDWR); if (devFd < 0) { LOGE("open /dev/fuse fail"); return E_MOUNT; } - // mount fuse mountpoint string opt = StringPrintf("fd=%i," "rootmode=40000," @@ -1542,8 +1536,7 @@ int32_t MountManager::MountMediaFuse(int32_t userId, int32_t &devFd) close(devFd); return E_MOUNT; } - - LOGI("mount %{public}s success", path.c_str()); + LOGI("mount media fuse success, path is %{public}s", path.c_str()); return E_OK; } -- Gitee From b169f0f539a06ec3b9e6aa298cdab45324d39b7b Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 13 Dec 2024 15:08:41 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/test/user_manager_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/storage_daemon/user/test/user_manager_test.cpp b/services/storage_daemon/user/test/user_manager_test.cpp index 010927f2..257d4ad1 100644 --- a/services/storage_daemon/user/test/user_manager_test.cpp +++ b/services/storage_daemon/user/test/user_manager_test.cpp @@ -289,7 +289,7 @@ HWTEST_F(UserManagerTest, Storage_Manager_UserManagerTest_StopUser_001, TestSize ASSERT_TRUE(userManager != nullptr); auto ret = userManager->StopUser(StorageTest::USER_ID2); - EXPECT_TRUE(ret == E_UMOUNT) << "dir is not mount"; + EXPECT_TRUE(ret == E_OK) << "dir mount success"; GTEST_LOG_(INFO) << "Storage_Manager_UserManagerTest_StopUser_001 end"; } @@ -314,7 +314,7 @@ HWTEST_F(UserManagerTest, Storage_Manager_UserManagerTest_StopUser_002, TestSize EXPECT_TRUE(ret == E_OK) << "create user dirs error"; ret = userManager->StopUser(StorageTest::USER_ID4); - EXPECT_TRUE(ret == E_UMOUNT) << "dir is not mount"; + EXPECT_TRUE(ret == E_OK) << "dir mount success"; userManager->DestroyUserDirs(StorageTest::USER_ID4, flags); KeyManager::GetInstance()->DeleteUserKeys(StorageTest::USER_ID4); @@ -619,7 +619,7 @@ HWTEST_F(UserManagerTest, Storage_Manager_MountManagerTest_MountMediaFuse_001, T int32_t userId = 101; int32_t devFd = -1; int32_t ret = mountManager->MountMediaFuse(userId, devFd); - EXPECT_EQ(ret, E_MOUNT); + EXPECT_EQ(ret, E_OK); ret = mountManager->UMountMediaFuse(userId); EXPECT_EQ(ret, E_OK); -- Gitee From fdf81e47b6250691bf49434c5aaf79b7583e3aa9 Mon Sep 17 00:00:00 2001 From: zhangchenyang Date: Fri, 13 Dec 2024 17:20:07 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E3=80=90master=E3=80=91=E3=80=90storage?= =?UTF-8?q?=5Fservice=E3=80=91=E8=A7=A3=E5=86=B3stop=20user=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchenyang --- services/storage_daemon/user/test/user_manager_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/storage_daemon/user/test/user_manager_test.cpp b/services/storage_daemon/user/test/user_manager_test.cpp index 257d4ad1..5a9cf45c 100644 --- a/services/storage_daemon/user/test/user_manager_test.cpp +++ b/services/storage_daemon/user/test/user_manager_test.cpp @@ -619,7 +619,7 @@ HWTEST_F(UserManagerTest, Storage_Manager_MountManagerTest_MountMediaFuse_001, T int32_t userId = 101; int32_t devFd = -1; int32_t ret = mountManager->MountMediaFuse(userId, devFd); - EXPECT_EQ(ret, E_OK); + EXPECT_EQ(ret, E_MOUNT); ret = mountManager->UMountMediaFuse(userId); EXPECT_EQ(ret, E_OK); -- Gitee