Merge "fs_mgr: init: adb: add fstab argument to fs_mgr_overlayfs_mount_all"

This commit is contained in:
Treehugger Robot 2018-09-25 20:37:15 +00:00 committed by Gerrit Code Review
commit 37d8bbdf9c
5 changed files with 26 additions and 28 deletions

View file

@ -216,8 +216,12 @@ void remount_service(unique_fd fd, const std::string& cmd) {
// If we can use overlayfs, lets get it in place first
// before we struggle with determining deduplication operations.
if (!verity_enabled && fs_mgr_overlayfs_setup() && fs_mgr_overlayfs_mount_all()) {
WriteFdExactly(fd.get(), "overlayfs mounted\n");
if (!verity_enabled && fs_mgr_overlayfs_setup()) {
std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
fs_mgr_free_fstab);
if (fs_mgr_overlayfs_mount_all(fstab.get())) {
WriteFdExactly(fd.get(), "overlayfs mounted\n");
}
}
// Find partitions that are deduplicated, and can be un-deduplicated.

View file

@ -569,8 +569,7 @@ static int fs_match(const char *in1, const char *in2)
* -1 on failure with errno set to match the 1st mount failure.
* 0 on success.
*/
static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_idx, int *attempted_idx)
{
static int mount_with_alternatives(fstab* fstab, int start_idx, int* end_idx, int* attempted_idx) {
int i;
int mount_errno = 0;
int mounted = 0;
@ -863,8 +862,7 @@ bool fs_mgr_update_checkpoint_partition(struct fstab_rec* rec) {
* first successful mount.
* Returns -1 on error, and FS_MGR_MNTALL_* otherwise.
*/
int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
{
int fs_mgr_mount_all(fstab* fstab, int mount_mode) {
int i = 0;
int encryptable = FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE;
int error_count = 0;
@ -1093,7 +1091,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
}
#if ALLOW_ADBD_DISABLE_VERITY == 1 // "userdebug" build
fs_mgr_overlayfs_mount_all();
fs_mgr_overlayfs_mount_all(fstab);
#endif
if (error_count) {
@ -1129,7 +1127,7 @@ int fs_mgr_do_mount_one(struct fstab_rec *rec)
* If multiple fstab entries are to be mounted on "n_name", it will try to mount each one
* in turn, and stop on 1st success, or no more match.
*/
static int fs_mgr_do_mount_helper(struct fstab* fstab, const char* n_name, char* n_blk_device,
static int fs_mgr_do_mount_helper(fstab* fstab, const char* n_name, char* n_blk_device,
char* tmp_mount_point, int need_checkpoint) {
int i = 0;
int mount_errors = 0;
@ -1244,13 +1242,12 @@ static int fs_mgr_do_mount_helper(struct fstab* fstab, const char* n_name, char*
return FS_MGR_DOMNT_FAILED;
}
int fs_mgr_do_mount(struct fstab* fstab, const char* n_name, char* n_blk_device,
char* tmp_mount_point) {
int fs_mgr_do_mount(fstab* fstab, const char* n_name, char* n_blk_device, char* tmp_mount_point) {
return fs_mgr_do_mount_helper(fstab, n_name, n_blk_device, tmp_mount_point, -1);
}
int fs_mgr_do_mount(struct fstab* fstab, const char* n_name, char* n_blk_device,
char* tmp_mount_point, bool needs_cp) {
int fs_mgr_do_mount(fstab* fstab, const char* n_name, char* n_blk_device, char* tmp_mount_point,
bool needs_cp) {
return fs_mgr_do_mount_helper(fstab, n_name, n_blk_device, tmp_mount_point, needs_cp);
}
@ -1276,8 +1273,7 @@ int fs_mgr_do_tmpfs_mount(const char *n_name)
/* This must be called after mount_all, because the mkswap command needs to be
* available.
*/
int fs_mgr_swapon_all(struct fstab *fstab)
{
int fs_mgr_swapon_all(fstab* fstab) {
int i = 0;
int flags = 0;
int err = 0;
@ -1367,7 +1363,7 @@ int fs_mgr_swapon_all(struct fstab *fstab)
return ret;
}
struct fstab_rec const* fs_mgr_get_crypt_entry(struct fstab const* fstab) {
struct fstab_rec const* fs_mgr_get_crypt_entry(fstab const* fstab) {
int i;
if (!fstab) {
@ -1391,7 +1387,7 @@ struct fstab_rec const* fs_mgr_get_crypt_entry(struct fstab const* fstab) {
*
* real_blk_device must be at least PROPERTY_VALUE_MAX bytes long
*/
void fs_mgr_get_crypt_info(struct fstab* fstab, char* key_loc, char* real_blk_device, size_t size) {
void fs_mgr_get_crypt_info(fstab* fstab, char* key_loc, char* real_blk_device, size_t size) {
struct fstab_rec const* rec = fs_mgr_get_crypt_entry(fstab);
if (key_loc) {
if (rec) {

View file

@ -49,7 +49,7 @@ using namespace std::literals;
#if ALLOW_ADBD_DISABLE_VERITY == 0 // If we are a user build, provide stubs
bool fs_mgr_overlayfs_mount_all() {
bool fs_mgr_overlayfs_mount_all(const fstab*) {
return false;
}
@ -195,8 +195,8 @@ bool fs_mgr_wants_overlayfs() {
}
bool fs_mgr_overlayfs_already_mounted(const std::string& mount_point) {
std::unique_ptr<struct fstab, decltype(&fs_mgr_free_fstab)> fstab(
fs_mgr_read_fstab("/proc/mounts"), fs_mgr_free_fstab);
std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab("/proc/mounts"),
fs_mgr_free_fstab);
if (!fstab) return false;
const auto lowerdir = kLowerdirOption + mount_point;
for (auto i = 0; i < fstab->num_entries; ++i) {
@ -400,16 +400,14 @@ std::vector<std::string> fs_mgr_candidate_list(const fstab* fstab,
} // namespace
bool fs_mgr_overlayfs_mount_all() {
bool fs_mgr_overlayfs_mount_all(const fstab* fstab) {
auto ret = false;
if (!fs_mgr_wants_overlayfs()) return ret;
std::unique_ptr<struct fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
fs_mgr_free_fstab);
if (!fstab) return ret;
for (const auto& mount_point : fs_mgr_candidate_list(fstab.get())) {
for (const auto& mount_point : fs_mgr_candidate_list(fstab)) {
if (fs_mgr_overlayfs_already_mounted(mount_point)) continue;
if (fs_mgr_overlayfs_mount(mount_point)) ret = true;
}
@ -432,8 +430,8 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool*
return ret;
}
std::unique_ptr<struct fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
fs_mgr_free_fstab);
std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
fs_mgr_free_fstab);
if (fstab && !fs_mgr_get_entry_for_mount_point(fstab.get(), kOverlayMountPoint)) return ret;
auto mounts = fs_mgr_candidate_list(fstab.get(), fs_mgr_mount_point(fstab.get(), mount_point));
if (fstab && mounts.empty()) return ret;
@ -464,7 +462,7 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool*
// If something is altered, set *change.
bool fs_mgr_overlayfs_teardown(const char* mount_point, bool* change) {
if (change) *change = false;
mount_point = fs_mgr_mount_point(std::unique_ptr<struct fstab, decltype(&fs_mgr_free_fstab)>(
mount_point = fs_mgr_mount_point(std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)>(
fs_mgr_read_fstab_default(), fs_mgr_free_fstab)
.get(),
mount_point);

View file

@ -20,7 +20,7 @@
#include <string>
bool fs_mgr_overlayfs_mount_all();
bool fs_mgr_overlayfs_mount_all(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);

View file

@ -388,7 +388,7 @@ bool FirstStageMount::MountPartitions() {
}
}
fs_mgr_overlayfs_mount_all();
fs_mgr_overlayfs_mount_all(device_tree_fstab_.get());
return true;
}