Increase early boot logging to kernel log
Make vold log warnings and errors to the kernel log until both
init_user0 has run and /data is mounted. Previously it only logged
errors, and not warnings, to the kernel log until /data is mounted.
This is helpful to diagnose failures of init_user0, since adb still
isn't started by that point.
Also, error messages can be misleading without seeing related warning
messages, e.g. the following which is expected on many devices:
E vold : keystore2 Keystore generateKey returned service specific error: -67
W vold : Failed to generate rollback-resistant key. This is
expected if keystore doesn't support rollback
resistance. Falling back to non-rollback-resistant key.
Therefore, increase the log level to WARNING and above.
Test: Intentionally broke fscrypt_init_user0(), then verified that the
error and warning messages appear in the kernel log on Cuttlefish.
Bug: 205314634
Bug: 222540970
Change-Id: Ia751f7c88cbf28caf81e891a518953cc0cee911e
diff --git a/main.cpp b/main.cpp
index 42789c9..b07ee68 100644
--- a/main.cpp
+++ b/main.cpp
@@ -16,6 +16,7 @@
#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER
+#include "FsCrypt.h"
#include "MetadataCrypt.h"
#include "NetlinkManager.h"
#include "VoldNativeService.h"
@@ -286,18 +287,24 @@
const char* tag, const char* file, unsigned int line, const char* message) {
logd_logger(log_buffer_id, severity, tag, file, line, message);
- if (severity >= android::base::ERROR) {
- static bool is_data_mounted = false;
+ if (severity >= android::base::WARNING) {
+ static bool early_boot_done = false;
- // When /data fails to mount, we don't have adb to get logcat. So until /data is
- // mounted we log errors to the kernel. This allows us to get failures via serial logs
- // and via last dmesg/"fastboot oem dmesg" on devices that support it.
+ // If metadata encryption setup (fscrypt_mount_metadata_encrypted) or
+ // basic FBE setup (fscrypt_init_user0) fails, then the boot will fail
+ // before adb can be started, so logcat won't be available. To allow
+ // debugging these early boot failures, log early errors and warnings to
+ // the kernel log. This allows diagnosing failures via the serial log,
+ // or via last dmesg/"fastboot oem dmesg" on devices that support it.
//
- // As a very quick-and-dirty test for /data, we check whether /data/misc/vold exists.
- if (is_data_mounted || access("/data/misc/vold", F_OK) == 0) {
- is_data_mounted = true;
- return;
+ // As a very quick-and-dirty test for whether /data has been mounted,
+ // check whether /data/misc/vold exists.
+ if (!early_boot_done) {
+ if (access("/data/misc/vold", F_OK) == 0 && fscrypt_init_user0_done) {
+ early_boot_done = true;
+ return;
+ }
+ android::base::KernelLogger(log_buffer_id, severity, tag, file, line, message);
}
- android::base::KernelLogger(log_buffer_id, severity, tag, file, line, message);
}
}