Remove fs_mgr_wait_for_file.
This transitions all callers to WaitForFile/WaitForFileDeleted. Bug: 134966533 Test: device boots Change-Id: Ic2107c97271adbd82094eda4ea6df3ccd652fd51
This commit is contained in:
parent
c65121306a
commit
5c475c70d0
5 changed files with 11 additions and 36 deletions
|
@ -56,6 +56,7 @@
|
|||
#include <ext4_utils/ext4_utils.h>
|
||||
#include <ext4_utils/wipe.h>
|
||||
#include <fs_avb/fs_avb.h>
|
||||
#include <fs_mgr/file_wait.h>
|
||||
#include <fs_mgr_overlayfs.h>
|
||||
#include <libdm/dm.h>
|
||||
#include <liblp/metadata_format.h>
|
||||
|
@ -116,28 +117,6 @@ enum FsStatFlags {
|
|||
FS_STAT_ENABLE_VERITY_FAILED = 0x80000,
|
||||
};
|
||||
|
||||
// TODO: switch to inotify()
|
||||
bool fs_mgr_wait_for_file(const std::string& filename,
|
||||
const std::chrono::milliseconds relative_timeout,
|
||||
FileWaitMode file_wait_mode) {
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
while (true) {
|
||||
int rv = access(filename.c_str(), F_OK);
|
||||
if (file_wait_mode == FileWaitMode::Exists) {
|
||||
if (!rv || errno != ENOENT) return true;
|
||||
} else if (file_wait_mode == FileWaitMode::DoesNotExist) {
|
||||
if (rv && errno == ENOENT) return true;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(50ms);
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time);
|
||||
if (time_elapsed > relative_timeout) return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void log_fs_stat(const std::string& blk_device, int fs_stat) {
|
||||
if ((fs_stat & FS_STAT_IS_EXT4) == 0) return; // only log ext4
|
||||
std::string msg =
|
||||
|
@ -1103,8 +1082,7 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (current_entry.fs_mgr_flags.wait &&
|
||||
!fs_mgr_wait_for_file(current_entry.blk_device, 20s)) {
|
||||
if (current_entry.fs_mgr_flags.wait && !WaitForFile(current_entry.blk_device, 20s)) {
|
||||
LERROR << "Skipping '" << current_entry.blk_device << "' during mount_all";
|
||||
continue;
|
||||
}
|
||||
|
@ -1373,7 +1351,7 @@ static int fs_mgr_do_mount_helper(Fstab* fstab, const std::string& n_name,
|
|||
}
|
||||
|
||||
// First check the filesystem if requested.
|
||||
if (fstab_entry.fs_mgr_flags.wait && !fs_mgr_wait_for_file(n_blk_device, 20s)) {
|
||||
if (fstab_entry.fs_mgr_flags.wait && !WaitForFile(n_blk_device, 20s)) {
|
||||
LERROR << "Skipping mounting '" << n_blk_device << "'";
|
||||
continue;
|
||||
}
|
||||
|
@ -1576,7 +1554,7 @@ bool fs_mgr_swapon_all(const Fstab& fstab) {
|
|||
fprintf(zram_fp.get(), "%" PRId64 "\n", entry.zram_size);
|
||||
}
|
||||
|
||||
if (entry.fs_mgr_flags.wait && !fs_mgr_wait_for_file(entry.blk_device, 20s)) {
|
||||
if (entry.fs_mgr_flags.wait && !WaitForFile(entry.blk_device, 20s)) {
|
||||
LERROR << "Skipping mkswap for '" << entry.blk_device << "'";
|
||||
ret = false;
|
||||
continue;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <fs_mgr/file_wait.h>
|
||||
#include <liblp/reader.h>
|
||||
|
||||
#include "fs_mgr_priv.h"
|
||||
|
@ -128,7 +129,7 @@ static bool CreateLogicalPartition(const LpMetadata& metadata, const LpMetadataP
|
|||
return false;
|
||||
}
|
||||
if (timeout_ms > std::chrono::milliseconds::zero()) {
|
||||
if (!fs_mgr_wait_for_file(*path, timeout_ms, FileWaitMode::Exists)) {
|
||||
if (!WaitForFile(*path, timeout_ms)) {
|
||||
DestroyLogicalPartition(name, {});
|
||||
LERROR << "Timed out waiting for device path: " << *path;
|
||||
return false;
|
||||
|
@ -202,7 +203,7 @@ bool UnmapDevice(const std::string& name, const std::chrono::milliseconds& timeo
|
|||
if (!dm.DeleteDevice(name)) {
|
||||
return false;
|
||||
}
|
||||
if (!path.empty() && !fs_mgr_wait_for_file(path, timeout_ms, FileWaitMode::DoesNotExist)) {
|
||||
if (!path.empty() && !WaitForFileDeleted(path, timeout_ms)) {
|
||||
LERROR << "Timed out waiting for device path to unlink: " << path;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include <android-base/unique_fd.h>
|
||||
#include <ext4_utils/ext4_utils.h>
|
||||
#include <fs_mgr.h>
|
||||
#include <fs_mgr/file_wait.h>
|
||||
#include <fs_mgr_dm_linear.h>
|
||||
#include <fs_mgr_overlayfs.h>
|
||||
#include <fstab/fstab.h>
|
||||
|
@ -867,7 +868,7 @@ bool fs_mgr_overlayfs_mount_all(Fstab* fstab) {
|
|||
scratch_can_be_mounted = false;
|
||||
auto scratch_device = fs_mgr_overlayfs_scratch_device();
|
||||
if (fs_mgr_overlayfs_scratch_can_be_mounted(scratch_device) &&
|
||||
fs_mgr_wait_for_file(scratch_device, 10s)) {
|
||||
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 */)) {
|
||||
|
|
|
@ -88,12 +88,6 @@
|
|||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
enum class FileWaitMode { Exists, DoesNotExist };
|
||||
|
||||
bool fs_mgr_wait_for_file(const std::string& filename,
|
||||
const std::chrono::milliseconds relative_timeout,
|
||||
FileWaitMode wait_mode = FileWaitMode::Exists);
|
||||
|
||||
bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly = true);
|
||||
bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab);
|
||||
bool fs_mgr_is_device_unlocked();
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <android-base/unique_fd.h>
|
||||
#include <crypto_utils/android_pubkey.h>
|
||||
#include <cutils/properties.h>
|
||||
#include <fs_mgr/file_wait.h>
|
||||
#include <libdm/dm.h>
|
||||
#include <logwrap/logwrap.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
|
@ -529,7 +530,7 @@ loaded:
|
|||
}
|
||||
|
||||
// make sure we've set everything up properly
|
||||
if (wait_for_verity_dev && !fs_mgr_wait_for_file(entry->blk_device, 1s)) {
|
||||
if (wait_for_verity_dev && !WaitForFile(entry->blk_device, 1s)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue