From e511e3a3b11bf43cd33a9a6f5e4ddcb8b03e45b5 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 29 Aug 2018 10:44:33 -0700 Subject: [PATCH 1/2] fs_mgr: Add fs_mgr_overlayfs_required_devices() Added fs_mgr_overlayfs_required_devices() as hint to init to make sure the device gets created before fs_mgr_overlayfs_mount_all(). Test: manual Bug: 109821005 Change-Id: Iab038f3e0252a357b082bb08db3679512b9badec --- fs_mgr/fs_mgr_overlayfs.cpp | 8 ++++++++ fs_mgr/include/fs_mgr_overlayfs.h | 2 ++ init/first_stage_mount.cpp | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp index ee63d60e8..e50ad2b7d 100644 --- a/fs_mgr/fs_mgr_overlayfs.cpp +++ b/fs_mgr/fs_mgr_overlayfs.cpp @@ -53,6 +53,10 @@ bool fs_mgr_overlayfs_mount_all(const fstab*) { return false; } +std::vector fs_mgr_overlayfs_required_devices(const fstab*) { + return {}; +} + bool fs_mgr_overlayfs_setup(const char*, const char*, bool* change) { if (change) *change = false; return false; @@ -467,6 +471,10 @@ bool fs_mgr_overlayfs_mount_all(const fstab* fstab) { return ret; } +std::vector fs_mgr_overlayfs_required_devices(const fstab*) { + return {}; +} + // Returns false if setup not permitted, errno set to last error. // If something is altered, set *change. bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool* change) { diff --git a/fs_mgr/include/fs_mgr_overlayfs.h b/fs_mgr/include/fs_mgr_overlayfs.h index 251dd9b91..3274e0ec3 100644 --- a/fs_mgr/include/fs_mgr_overlayfs.h +++ b/fs_mgr/include/fs_mgr_overlayfs.h @@ -19,8 +19,10 @@ #include #include +#include bool fs_mgr_overlayfs_mount_all(const fstab* fstab); +std::vector fs_mgr_overlayfs_required_devices(const fstab* fstab); bool fs_mgr_overlayfs_setup(const char* backing = nullptr, const char* mount_point = nullptr, bool* change = nullptr); bool fs_mgr_overlayfs_teardown(const char* mount_point = nullptr, bool* change = nullptr); diff --git a/init/first_stage_mount.cpp b/init/first_stage_mount.cpp index 684bf1f13..eb86eb087 100644 --- a/init/first_stage_mount.cpp +++ b/init/first_stage_mount.cpp @@ -391,6 +391,12 @@ bool FirstStageMount::MountPartitions() { } } + // heads up for instantiating required device(s) for overlayfs logic + const auto devices = fs_mgr_overlayfs_required_devices(device_tree_fstab_.get()); + for (auto const& device : devices) { + InitMappedDevice(device); + } + fs_mgr_overlayfs_mount_all(device_tree_fstab_.get()); return true; From 780db02f7d6bfa2e0233521d3aa105d3c10ce8af Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 6 Jun 2018 13:10:40 -0700 Subject: [PATCH 2/2] fs_mgr: split out fs_mgr_overlayfs_setup_dir() In preparation for adding a list of possible backing storage. Test: compile Bug: 109821005 Change-Id: If3664d44c232db32f79b1355799ec239cfe7633a --- fs_mgr/fs_mgr_overlayfs.cpp | 38 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp index e50ad2b7d..1edd573d4 100644 --- a/fs_mgr/fs_mgr_overlayfs.cpp +++ b/fs_mgr/fs_mgr_overlayfs.cpp @@ -298,6 +298,28 @@ bool fs_mgr_rm_all(const std::string& path, bool* change = nullptr) { constexpr char kOverlayfsFileContext[] = "u:object_r:overlayfs_file:s0"; +bool fs_mgr_overlayfs_setup_dir(const std::string& dir, std::string* overlay, bool* change) { + auto ret = true; + auto top = dir + kOverlayTopDir; + if (setfscreatecon(kOverlayfsFileContext)) { + ret = false; + PERROR << "setfscreatecon " << kOverlayfsFileContext; + } + auto save_errno = errno; + if (!mkdir(top.c_str(), 0755)) { + if (change) *change = true; + } else if (errno != EEXIST) { + ret = false; + PERROR << "mkdir " << top; + } else { + errno = save_errno; + } + setfscreatecon(nullptr); + + if (overlay) *overlay = std::move(top); + return ret; +} + bool fs_mgr_overlayfs_setup_one(const std::string& overlay, const std::string& mount_point, bool* change) { auto ret = true; @@ -497,19 +519,9 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool* auto mounts = fs_mgr_candidate_list(fstab.get(), fs_mgr_mount_point(fstab.get(), mount_point)); if (fstab && mounts.empty()) return ret; - if (setfscreatecon(kOverlayfsFileContext)) { - PERROR << "setfscreatecon " << kOverlayfsFileContext; - } - auto overlay = kOverlayMountPoint + kOverlayTopDir; - auto save_errno = errno; - if (!mkdir(overlay.c_str(), 0755)) { - if (change) *change = true; - } else if (errno != EEXIST) { - PERROR << "mkdir " << overlay; - } else { - errno = save_errno; - } - setfscreatecon(nullptr); + std::string overlay; + ret |= fs_mgr_overlayfs_setup_dir(kOverlayMountPoint, &overlay, change); + if (!fstab && mount_point && fs_mgr_overlayfs_setup_one(overlay, mount_point, change)) { ret = true; }