Merge changes I819eb60a,I48a52aa0,Iab04742c into main
* changes:
init: Reorder GetBlockDeviceSymlinks() so FindDmDevice() is first
init: Add partition_uuid to Uevent
fs_mgr: Add getter for androidboot.boot_part_uuid
diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp
index 6e4cae1..43547ea 100644
--- a/fs_mgr/libfstab/fstab.cpp
+++ b/fs_mgr/libfstab/fstab.cpp
@@ -950,6 +950,22 @@
return ExtraBootDevices(fstab);
}
+std::string GetBootPartUuid() {
+ std::string boot_part_uuid;
+
+ if (GetBootconfig("androidboot.boot_part_uuid", &boot_part_uuid)) {
+ return boot_part_uuid;
+ }
+
+ ImportKernelCmdline([&](std::string key, std::string value) {
+ if (key == "androidboot.boot_part_uuid") {
+ boot_part_uuid = value;
+ }
+ });
+
+ return boot_part_uuid;
+}
+
std::string GetVerityDeviceName(const FstabEntry& entry) {
std::string base_device;
if (entry.mount_point == "/") {
diff --git a/fs_mgr/libfstab/include/fstab/fstab.h b/fs_mgr/libfstab/include/fstab/fstab.h
index 070dd91..0ff3188 100644
--- a/fs_mgr/libfstab/include/fstab/fstab.h
+++ b/fs_mgr/libfstab/include/fstab/fstab.h
@@ -126,6 +126,16 @@
std::set<std::string> GetBootDevices();
+// Get the Partition UUID the kernel loaded from if the bootloader passed it.
+//
+// If the kernel's Partition UUID is provided then we can use this to help
+// identify which block device contains the filesystems we care about.
+//
+// NOTE: Nothing secures a UUID other than the convention that two disks
+// aren't supposed to both have the same UUID. We still need other mechanisms
+// to ensure we've got the right disk.
+std::string GetBootPartUuid();
+
// Return the name of the dm-verity device for the given fstab entry. This does
// not check whether the device is valid or exists; it merely returns the
// expected name.
diff --git a/init/devices.cpp b/init/devices.cpp
index f2bb9d2..0af843f 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -376,7 +376,13 @@
std::string partition;
std::string uuid;
- if (FindPlatformDevice(uevent.path, &device)) {
+ if (FindDmDevice(uevent, &partition, &uuid)) {
+ std::vector<std::string> symlinks = {"/dev/block/mapper/" + partition};
+ if (!uuid.empty()) {
+ symlinks.emplace_back("/dev/block/mapper/by-uuid/" + uuid);
+ }
+ return symlinks;
+ } else if (FindPlatformDevice(uevent.path, &device)) {
// Skip /devices/platform or /devices/ if present
static constexpr std::string_view devices_platform_prefix = "/devices/platform/";
static constexpr std::string_view devices_prefix = "/devices/";
@@ -392,12 +398,6 @@
type = "pci";
} else if (FindVbdDevicePrefix(uevent.path, &device)) {
type = "vbd";
- } else if (FindDmDevice(uevent, &partition, &uuid)) {
- std::vector<std::string> symlinks = {"/dev/block/mapper/" + partition};
- if (!uuid.empty()) {
- symlinks.emplace_back("/dev/block/mapper/by-uuid/" + uuid);
- }
- return symlinks;
} else {
return {};
}
diff --git a/init/uevent.h b/init/uevent.h
index dc35fd9..c8ca52a 100644
--- a/init/uevent.h
+++ b/init/uevent.h
@@ -28,6 +28,7 @@
std::string subsystem;
std::string firmware;
std::string partition_name;
+ std::string partition_uuid;
std::string device_name;
std::string modalias;
int partition_num;
diff --git a/init/uevent_listener.cpp b/init/uevent_listener.cpp
index 5da6777..97f3de6 100644
--- a/init/uevent_listener.cpp
+++ b/init/uevent_listener.cpp
@@ -66,6 +66,9 @@
} else if (!strncmp(msg, "PARTNAME=", 9)) {
msg += 9;
uevent->partition_name = msg;
+ } else if (!strncmp(msg, "PARTUUID=", 9)) {
+ msg += 9;
+ uevent->partition_uuid = msg;
} else if (!strncmp(msg, "DEVNAME=", 8)) {
msg += 8;
uevent->device_name = msg;
@@ -82,7 +85,7 @@
if (LOG_UEVENTS) {
LOG(INFO) << "event { '" << uevent->action << "', '" << uevent->path << "', '"
<< uevent->subsystem << "', '" << uevent->firmware << "', " << uevent->major
- << ", " << uevent->minor << " }";
+ << ", " << uevent->minor << ", " << uevent->partition_uuid << " }";
}
}