Merge "Only store result of mount_all that mounted userdata" am: edc501d674

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1420053

Change-Id: I444f74692633b2bc4f5bcf03cd036b5c52b120aa
This commit is contained in:
Nikita Ioffe 2020-09-08 23:10:11 +00:00 committed by Automerger Merge Worker
commit 4e311d69b5
3 changed files with 38 additions and 14 deletions

View file

@ -1316,14 +1316,15 @@ static bool IsMountPointMounted(const std::string& mount_point) {
// When multiple fstab records share the same mount_point, it will try to mount each
// one in turn, and ignore any duplicates after a first successful mount.
// Returns -1 on error, and FS_MGR_MNTALL_* otherwise.
int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
MountAllResult fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
int encryptable = FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE;
int error_count = 0;
CheckpointManager checkpoint_manager;
AvbUniquePtr avb_handle(nullptr);
bool userdata_mounted = false;
if (fstab->empty()) {
return FS_MGR_MNTALL_FAIL;
return {FS_MGR_MNTALL_FAIL, userdata_mounted};
}
// Keep i int to prevent unsigned integer overflow from (i = top_idx - 1),
@ -1363,7 +1364,7 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
}
// Terrible hack to make it possible to remount /data.
// TODO: refact fs_mgr_mount_all and get rid of this.
// TODO: refactor fs_mgr_mount_all and get rid of this.
if (mount_mode == MOUNT_MODE_ONLY_USERDATA && current_entry.mount_point != "/data") {
continue;
}
@ -1400,7 +1401,7 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
if (!avb_handle) {
LERROR << "Failed to open AvbHandle";
set_type_property(encryptable);
return FS_MGR_MNTALL_FAIL;
return {FS_MGR_MNTALL_FAIL, userdata_mounted};
}
}
if (avb_handle->SetUpAvbHashtree(&current_entry, true /* wait_for_verity_dev */) ==
@ -1442,7 +1443,7 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
if (status == FS_MGR_MNTALL_FAIL) {
// Fatal error - no point continuing.
return status;
return {status, userdata_mounted};
}
if (status != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) {
@ -1457,11 +1458,14 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
nullptr)) {
LERROR << "Encryption failed";
set_type_property(encryptable);
return FS_MGR_MNTALL_FAIL;
return {FS_MGR_MNTALL_FAIL, userdata_mounted};
}
}
}
if (current_entry.mount_point == "/data") {
userdata_mounted = true;
}
// Success! Go get the next one.
continue;
}
@ -1561,9 +1565,9 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
#endif
if (error_count) {
return FS_MGR_MNTALL_FAIL;
return {FS_MGR_MNTALL_FAIL, userdata_mounted};
} else {
return encryptable;
return {encryptable, userdata_mounted};
}
}
@ -1785,8 +1789,8 @@ int fs_mgr_remount_userdata_into_checkpointing(Fstab* fstab) {
}
LINFO << "Remounting /data";
// TODO(b/143970043): remove this hack after fs_mgr_mount_all is refactored.
int result = fs_mgr_mount_all(fstab, MOUNT_MODE_ONLY_USERDATA);
return result == FS_MGR_MNTALL_FAIL ? -1 : 0;
auto result = fs_mgr_mount_all(fstab, MOUNT_MODE_ONLY_USERDATA);
return result.code == FS_MGR_MNTALL_FAIL ? -1 : 0;
}
return 0;
}

View file

@ -60,8 +60,20 @@ enum mount_mode {
#define FS_MGR_MNTALL_DEV_NOT_ENCRYPTED 1
#define FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE 0
#define FS_MGR_MNTALL_FAIL (-1)
struct MountAllResult {
// One of the FS_MGR_MNTALL_* returned code defined above.
int code;
// Whether userdata was mounted as a result of |fs_mgr_mount_all| call.
bool userdata_mounted;
};
// fs_mgr_mount_all() updates fstab entries that reference device-mapper.
int fs_mgr_mount_all(android::fs_mgr::Fstab* fstab, int mount_mode);
// Returns a |MountAllResult|. The first element is one of the FS_MNG_MNTALL_* return codes
// defined above, and the second element tells whether this call to fs_mgr_mount_all was responsible
// for mounting userdata. Later is required for init to correctly enqueue fs-related events as part
// of userdata remount during userspace reboot.
MountAllResult fs_mgr_mount_all(android::fs_mgr::Fstab* fstab, int mount_mode);
#define FS_MGR_DOMNT_FAILED (-1)
#define FS_MGR_DOMNT_BUSY (-2)

View file

@ -662,18 +662,26 @@ static Result<void> do_mount_all(const BuiltinArguments& args) {
}
}
auto mount_fstab_return_code = fs_mgr_mount_all(&fstab, mount_all->mode);
auto mount_fstab_result = fs_mgr_mount_all(&fstab, mount_all->mode);
SetProperty(prop_name, std::to_string(t.duration().count()));
if (mount_all->import_rc) {
import_late(mount_all->rc_paths);
}
if (mount_fstab_result.userdata_mounted) {
// This call to fs_mgr_mount_all mounted userdata. Keep the result in
// order for userspace reboot to correctly remount userdata.
LOG(INFO) << "Userdata mounted using "
<< (mount_all->fstab_path.empty() ? "(default fstab)" : mount_all->fstab_path)
<< " result : " << mount_fstab_result.code;
initial_mount_fstab_return_code = mount_fstab_result.code;
}
if (queue_event) {
/* queue_fs_event will queue event based on mount_fstab return code
* and return processed return code*/
initial_mount_fstab_return_code = mount_fstab_return_code;
auto queue_fs_result = queue_fs_event(mount_fstab_return_code, false);
auto queue_fs_result = queue_fs_event(mount_fstab_result.code, false);
if (!queue_fs_result.ok()) {
return Error() << "queue_fs_event() failed: " << queue_fs_result.error();
}