From cd720dc31370ec4352a4e7a47405b22c187c6d38 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 10 Dec 2019 21:08:08 -0800 Subject: [PATCH] remount: Factor some code out of fs_mgr_overlayfs_mount_all(). To ease on the indentation, this factors the innermost code of overlayfs_mountall() into a new TryMountScratch() function. Bug: 134949511 Test: adb remount Change-Id: I894cbcd17bb6bd64751f235a074fa5ba7ce5157c --- fs_mgr/fs_mgr_overlayfs.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp index 0579a3d5b..05f3311cf 100644 --- a/fs_mgr/fs_mgr_overlayfs.cpp +++ b/fs_mgr/fs_mgr_overlayfs.cpp @@ -1066,6 +1066,25 @@ Fstab fs_mgr_overlayfs_candidate_list(const Fstab& fstab) { return candidates; } +static void TryMountScratch() { + auto scratch_device = fs_mgr_overlayfs_scratch_device(); + if (!fs_mgr_overlayfs_scratch_can_be_mounted(scratch_device)) { + return; + } + if (!WaitForFile(scratch_device, 10s)) { + return; + } + const auto mount_type = fs_mgr_overlayfs_scratch_mount_type(); + if (!fs_mgr_overlayfs_mount_scratch(scratch_device, mount_type, true /* readonly */)) { + return; + } + auto has_overlayfs_dir = fs_mgr_access(kScratchMountPoint + kOverlayTopDir); + fs_mgr_overlayfs_umount_scratch(); + if (has_overlayfs_dir) { + fs_mgr_overlayfs_mount_scratch(scratch_device, mount_type); + } +} + bool fs_mgr_overlayfs_mount_all(Fstab* fstab) { auto ret = false; if (fs_mgr_overlayfs_invalid()) return ret; @@ -1080,19 +1099,7 @@ bool fs_mgr_overlayfs_mount_all(Fstab* fstab) { } if (scratch_can_be_mounted) { scratch_can_be_mounted = false; - auto scratch_device = fs_mgr_overlayfs_scratch_device(); - if (fs_mgr_overlayfs_scratch_can_be_mounted(scratch_device) && - WaitForFile(scratch_device, 10s)) { - const auto mount_type = fs_mgr_overlayfs_scratch_mount_type(); - if (fs_mgr_overlayfs_mount_scratch(scratch_device, mount_type, - true /* readonly */)) { - auto has_overlayfs_dir = fs_mgr_access(kScratchMountPoint + kOverlayTopDir); - fs_mgr_overlayfs_umount_scratch(); - if (has_overlayfs_dir) { - fs_mgr_overlayfs_mount_scratch(scratch_device, mount_type); - } - } - } + TryMountScratch(); } if (fs_mgr_overlayfs_mount(mount_point)) ret = true; }