summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Desprez <jdesprez@google.com>2024-04-18 18:13:55 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-18 18:13:55 +0000
commita078141ec8b073fd90796b98bd501f2a3a41e12c (patch)
tree8844b4ba0f263ca3cf391c09eda37c268a47ceb7
parent8a92f2d7472245616e880e84b93e5873bb3e4ab2 (diff)
parentfa5cf6884a9507e9b78a11c9c439a2500a75b83a (diff)
downloadcore-a078141ec8b073fd90796b98bd501f2a3a41e12c.tar.gz
Merge "snapshotctl: Check for cow path when allocated from /data" into main
-rw-r--r--fs_mgr/libsnapshot/snapshotctl.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/fs_mgr/libsnapshot/snapshotctl.cpp b/fs_mgr/libsnapshot/snapshotctl.cpp
index 192e1d67a..0158d4d9c 100644
--- a/fs_mgr/libsnapshot/snapshotctl.cpp
+++ b/fs_mgr/libsnapshot/snapshotctl.cpp
@@ -110,6 +110,7 @@ class MapSnapshots {
private:
std::optional<std::string> GetCowImagePath(std::string& name);
bool PrepareUpdate();
+ bool GetCowDevicePath(std::string partition_name, std::string* cow_path);
bool WriteSnapshotPatch(std::string cow_device, std::string patch);
std::string GetGroupName(const android::fs_mgr::LpMetadata& pt,
const std::string& partiton_name);
@@ -231,6 +232,23 @@ bool MapSnapshots::PrepareUpdate() {
return true;
}
+bool MapSnapshots::GetCowDevicePath(std::string partition_name, std::string* cow_path) {
+ auto& dm = android::dm::DeviceMapper::Instance();
+ std::string cow_device = partition_name + "-cow";
+ if (dm.GetDmDevicePathByName(cow_device, cow_path)) {
+ return true;
+ }
+
+ LOG(INFO) << "Failed to find cow path: " << cow_device << " Checking the device for -img path";
+ // If the COW device exists only on /data
+ cow_device = partition_name + "-cow-img";
+ if (!dm.GetDmDevicePathByName(cow_device, cow_path)) {
+ LOG(ERROR) << "Failed to cow path: " << cow_device;
+ return false;
+ }
+ return true;
+}
+
bool MapSnapshots::ApplyUpdate() {
if (!PrepareUpdate()) {
LOG(ERROR) << "PrepareUpdate failed";
@@ -253,15 +271,13 @@ bool MapSnapshots::ApplyUpdate() {
LOG(INFO) << "MapAllSnapshots success";
- auto& dm = android::dm::DeviceMapper::Instance();
auto target_slot = fs_mgr_get_other_slot_suffix();
for (auto& patchfile : patchfiles_) {
auto npos = patchfile.rfind(".patch");
auto partition_name = patchfile.substr(0, npos) + target_slot;
- auto cow_device = partition_name + "-cow";
std::string cow_path;
- if (!dm.GetDmDevicePathByName(cow_device, &cow_path)) {
- LOG(ERROR) << "Failed to cow path";
+ if (!GetCowDevicePath(partition_name, &cow_path)) {
+ LOG(ERROR) << "Failed to find cow path";
return false;
}
threads_.emplace_back(std::async(std::launch::async, &MapSnapshots::WriteSnapshotPatch,