Loading fs_mgr/libsnapshot/snapshot.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -1619,6 +1619,18 @@ bool SnapshotManager::RemoveAllSnapshots(LockedFile* lock) { // as dm-snapshot (for example, after merge completes). bool should_unmap = current_slot != Slot::Target; bool should_delete = ShouldDeleteSnapshot(flashing_status, current_slot, name); if (should_unmap && android::base::EndsWith(name, device_->GetSlotSuffix())) { // Something very unexpected has happened - we want to unmap this // snapshot, but it's on the wrong slot. We can't unmap an active // partition. If this is not really a snapshot, skip the unmap // step. auto& dm = DeviceMapper::Instance(); if (dm.GetState(name) == DmDeviceState::INVALID || !IsSnapshotDevice(name)) { LOG(ERROR) << "Detected snapshot " << name << " on " << current_slot << " slot" << " for source partition; removing without unmap."; should_unmap = false; } } bool partition_ok = true; if (should_unmap && !UnmapPartitionWithSnapshot(lock, name)) { Loading fs_mgr/libsnapshot/snapshot_test.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -2021,6 +2021,34 @@ TEST_F(SnapshotUpdateTest, MapAllSnapshots) { ASSERT_TRUE(IsPartitionUnchanged("sys_b")); } TEST_F(SnapshotUpdateTest, CancelOnTargetSlot) { AddOperationForPartitions(); // Execute the update from B->A. test_device->set_slot_suffix("_b"); ASSERT_TRUE(sm->BeginUpdate()); ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_)); std::string path; ASSERT_TRUE(CreateLogicalPartition( CreateLogicalPartitionParams{ .block_device = fake_super, .metadata_slot = 0, .partition_name = "sys_a", .timeout_ms = 1s, .partition_opener = opener_.get(), }, &path)); // Hold sys_a open so it can't be unmapped. unique_fd fd(open(path.c_str(), O_RDONLY)); // Switch back to "A", make sure we can cancel. Instead of unmapping sys_a // we should simply delete the old snapshots. test_device->set_slot_suffix("_a"); ASSERT_TRUE(sm->BeginUpdate()); } class FlashAfterUpdateTest : public SnapshotUpdateTest, public WithParamInterface<std::tuple<uint32_t, bool>> { public: Loading rootdir/init.rc +9 −7 Original line number Diff line number Diff line Loading @@ -821,6 +821,9 @@ on post-fs-data mkdir /data/ss 0700 system system encryption=Require mkdir /data/system 0775 system system encryption=Require mkdir /data/system/environ 0700 system system # b/183861600 attempt to fix selinux label before running derive_classpath service restorecon /data/system/environ mkdir /data/system/dropbox 0700 system system mkdir /data/system/heapdump 0700 system system mkdir /data/system/users 0775 system system Loading Loading @@ -884,13 +887,6 @@ on post-fs-data wait_for_prop apexd.status activated perform_apex_config # Define and export *CLASSPATH variables mkdir /data/system/environ 0700 system system # Must start before 'odsign', as odsign depends on *CLASSPATH variables exec_start derive_classpath load_exports /data/system/environ/classpath rm /data/system/environ/classpath # Special-case /data/media/obb per b/64566063 mkdir /data/media 0770 media_rw media_rw encryption=None exec - media_rw media_rw -- /system/bin/chattr +F /data/media Loading @@ -903,6 +899,12 @@ on post-fs-data # Set SELinux security contexts on upgrade or policy update. restorecon --recursive --skip-ce /data # Define and export *CLASSPATH variables # Must start before 'odsign', as odsign depends on *CLASSPATH variables exec_start derive_classpath load_exports /data/system/environ/classpath rm /data/system/environ/classpath # Start the on-device signing daemon, and wait for it to finish, to ensure # ART artifacts are generated if needed. # Must start after 'derive_classpath' to have *CLASSPATH variables set. Loading Loading
fs_mgr/libsnapshot/snapshot.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -1619,6 +1619,18 @@ bool SnapshotManager::RemoveAllSnapshots(LockedFile* lock) { // as dm-snapshot (for example, after merge completes). bool should_unmap = current_slot != Slot::Target; bool should_delete = ShouldDeleteSnapshot(flashing_status, current_slot, name); if (should_unmap && android::base::EndsWith(name, device_->GetSlotSuffix())) { // Something very unexpected has happened - we want to unmap this // snapshot, but it's on the wrong slot. We can't unmap an active // partition. If this is not really a snapshot, skip the unmap // step. auto& dm = DeviceMapper::Instance(); if (dm.GetState(name) == DmDeviceState::INVALID || !IsSnapshotDevice(name)) { LOG(ERROR) << "Detected snapshot " << name << " on " << current_slot << " slot" << " for source partition; removing without unmap."; should_unmap = false; } } bool partition_ok = true; if (should_unmap && !UnmapPartitionWithSnapshot(lock, name)) { Loading
fs_mgr/libsnapshot/snapshot_test.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -2021,6 +2021,34 @@ TEST_F(SnapshotUpdateTest, MapAllSnapshots) { ASSERT_TRUE(IsPartitionUnchanged("sys_b")); } TEST_F(SnapshotUpdateTest, CancelOnTargetSlot) { AddOperationForPartitions(); // Execute the update from B->A. test_device->set_slot_suffix("_b"); ASSERT_TRUE(sm->BeginUpdate()); ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_)); std::string path; ASSERT_TRUE(CreateLogicalPartition( CreateLogicalPartitionParams{ .block_device = fake_super, .metadata_slot = 0, .partition_name = "sys_a", .timeout_ms = 1s, .partition_opener = opener_.get(), }, &path)); // Hold sys_a open so it can't be unmapped. unique_fd fd(open(path.c_str(), O_RDONLY)); // Switch back to "A", make sure we can cancel. Instead of unmapping sys_a // we should simply delete the old snapshots. test_device->set_slot_suffix("_a"); ASSERT_TRUE(sm->BeginUpdate()); } class FlashAfterUpdateTest : public SnapshotUpdateTest, public WithParamInterface<std::tuple<uint32_t, bool>> { public: Loading
rootdir/init.rc +9 −7 Original line number Diff line number Diff line Loading @@ -821,6 +821,9 @@ on post-fs-data mkdir /data/ss 0700 system system encryption=Require mkdir /data/system 0775 system system encryption=Require mkdir /data/system/environ 0700 system system # b/183861600 attempt to fix selinux label before running derive_classpath service restorecon /data/system/environ mkdir /data/system/dropbox 0700 system system mkdir /data/system/heapdump 0700 system system mkdir /data/system/users 0775 system system Loading Loading @@ -884,13 +887,6 @@ on post-fs-data wait_for_prop apexd.status activated perform_apex_config # Define and export *CLASSPATH variables mkdir /data/system/environ 0700 system system # Must start before 'odsign', as odsign depends on *CLASSPATH variables exec_start derive_classpath load_exports /data/system/environ/classpath rm /data/system/environ/classpath # Special-case /data/media/obb per b/64566063 mkdir /data/media 0770 media_rw media_rw encryption=None exec - media_rw media_rw -- /system/bin/chattr +F /data/media Loading @@ -903,6 +899,12 @@ on post-fs-data # Set SELinux security contexts on upgrade or policy update. restorecon --recursive --skip-ce /data # Define and export *CLASSPATH variables # Must start before 'odsign', as odsign depends on *CLASSPATH variables exec_start derive_classpath load_exports /data/system/environ/classpath rm /data/system/environ/classpath # Start the on-device signing daemon, and wait for it to finish, to ensure # ART artifacts are generated if needed. # Must start after 'derive_classpath' to have *CLASSPATH variables set. Loading