summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-01-10 11:25:35 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-01-10 11:25:35 +0000
commite860e8779f9288b28e81f5c3dcbc17fc83ff4b76 (patch)
treee2f9265e32d9b88a5c5eca7654f01bae019af40b
parenta896f1b17944ad429b96cee2a9210b63f791618b (diff)
parent5582eaf14ab7b6d63670c5fac672030d4bf129fb (diff)
Snap for 9473050 from 5582eaf14ab7b6d63670c5fac672030d4bf129fb to t-keystone-qcom-release
Change-Id: Ic6ff9bf2d5ec87ae237d15fe81e14b3a82c8ea79
-rw-r--r--fs_mgr/libdm/dm.cpp24
-rw-r--r--fs_mgr/libdm/include/libdm/dm.h6
2 files changed, 30 insertions, 0 deletions
diff --git a/fs_mgr/libdm/dm.cpp b/fs_mgr/libdm/dm.cpp
index 0624fe0fc..deffae1ad 100644
--- a/fs_mgr/libdm/dm.cpp
+++ b/fs_mgr/libdm/dm.cpp
@@ -20,6 +20,7 @@
#include <sys/ioctl.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
+#include <sys/utsname.h>
#include <chrono>
#include <functional>
@@ -711,5 +712,28 @@ std::map<std::string, std::string> DeviceMapper::FindDmPartitions() {
return dm_block_devices;
}
+bool DeviceMapper::CreatePlaceholderDevice(const std::string& name) {
+ if (!CreateEmptyDevice(name)) {
+ return false;
+ }
+
+ struct utsname uts;
+ unsigned int major, minor;
+ if (uname(&uts) != 0 || sscanf(uts.release, "%u.%u", &major, &minor) != 2) {
+ LOG(ERROR) << "Could not parse the kernel version from uname";
+ return true;
+ }
+
+ // On Linux 5.15+, there is no uevent until DM_TABLE_LOAD.
+ if (major > 5 || (major == 5 && minor >= 15)) {
+ DmTable table;
+ table.Emplace<DmTargetError>(0, 1);
+ if (!LoadTable(name, table)) {
+ return false;
+ }
+ }
+ return true;
+}
+
} // namespace dm
} // namespace android
diff --git a/fs_mgr/libdm/include/libdm/dm.h b/fs_mgr/libdm/include/libdm/dm.h
index f17ae1338..dbef8f902 100644
--- a/fs_mgr/libdm/include/libdm/dm.h
+++ b/fs_mgr/libdm/include/libdm/dm.h
@@ -292,6 +292,12 @@ class DeviceMapper final : public IDeviceMapper {
// Returns mapping <partition-name, /dev/block/dm-x>
std::map<std::string, std::string> FindDmPartitions();
+ // Create a placeholder device. This is useful for ensuring that a uevent is in the pipeline,
+ // to reduce the amount of time a future WaitForDevice will block. On kernels < 5.15, this
+ // simply calls CreateEmptyDevice. On 5.15 and higher, it also loads (but does not activate)
+ // a placeholder table containing dm-error.
+ bool CreatePlaceholderDevice(const std::string& name);
+
private:
// Maximum possible device mapper targets registered in the kernel.
// This is only used to read the list of targets from kernel so we allocate