Shutdown f2fs to avoid fsck
Bug: 229406072 Signed-off-by: Jaegeuk Kim <jaegeuk@google.com> Change-Id: Id3b27219ab2a4655f1740829b0f03f027e66349d Merged-In: Id3b27219ab2a4655f1740829b0f03f027e66349d
This commit is contained in:
parent
a5867617af
commit
7e0df03bc9
1 changed files with 14 additions and 3 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <linux/f2fs.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/loop.h>
|
#include <linux/loop.h>
|
||||||
#include <mntent.h>
|
#include <mntent.h>
|
||||||
|
|
@ -218,7 +219,7 @@ static void LogShutdownTime(UmountStat stat, Timer* t) {
|
||||||
<< stat;
|
<< stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsDataMounted() {
|
static bool IsDataMounted(const std::string& fstype) {
|
||||||
std::unique_ptr<std::FILE, int (*)(std::FILE*)> fp(setmntent("/proc/mounts", "re"), endmntent);
|
std::unique_ptr<std::FILE, int (*)(std::FILE*)> fp(setmntent("/proc/mounts", "re"), endmntent);
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) {
|
||||||
PLOG(ERROR) << "Failed to open /proc/mounts";
|
PLOG(ERROR) << "Failed to open /proc/mounts";
|
||||||
|
|
@ -227,7 +228,7 @@ static bool IsDataMounted() {
|
||||||
mntent* mentry;
|
mntent* mentry;
|
||||||
while ((mentry = getmntent(fp.get())) != nullptr) {
|
while ((mentry = getmntent(fp.get())) != nullptr) {
|
||||||
if (mentry->mnt_dir == "/data"s) {
|
if (mentry->mnt_dir == "/data"s) {
|
||||||
return true;
|
return fstype == "*" || mentry->mnt_type == fstype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -633,7 +634,7 @@ static void DoReboot(unsigned int cmd, const std::string& reason, const std::str
|
||||||
|
|
||||||
// If /data isn't mounted then we can skip the extra reboot steps below, since we don't need to
|
// If /data isn't mounted then we can skip the extra reboot steps below, since we don't need to
|
||||||
// worry about unmounting it.
|
// worry about unmounting it.
|
||||||
if (!IsDataMounted()) {
|
if (!IsDataMounted("*")) {
|
||||||
sync();
|
sync();
|
||||||
RebootSystem(cmd, reboot_target);
|
RebootSystem(cmd, reboot_target);
|
||||||
abort();
|
abort();
|
||||||
|
|
@ -758,6 +759,16 @@ static void DoReboot(unsigned int cmd, const std::string& reason, const std::str
|
||||||
sem_post(&reboot_semaphore);
|
sem_post(&reboot_semaphore);
|
||||||
|
|
||||||
// Reboot regardless of umount status. If umount fails, fsck after reboot will fix it.
|
// Reboot regardless of umount status. If umount fails, fsck after reboot will fix it.
|
||||||
|
if (IsDataMounted("f2fs")) {
|
||||||
|
uint32_t flag = F2FS_GOING_DOWN_FULLSYNC;
|
||||||
|
unique_fd fd(TEMP_FAILURE_RETRY(open("/data", O_RDONLY)));
|
||||||
|
int ret = ioctl(fd, F2FS_IOC_SHUTDOWN, &flag);
|
||||||
|
if (ret) {
|
||||||
|
PLOG(ERROR) << "Shutdown /data: ";
|
||||||
|
} else {
|
||||||
|
LOG(INFO) << "Shutdown /data";
|
||||||
|
}
|
||||||
|
}
|
||||||
RebootSystem(cmd, reboot_target);
|
RebootSystem(cmd, reboot_target);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue