Loading fs_mgr/libsnapshot/android/snapshot/snapshot.proto +4 −2 Original line number Diff line number Diff line Loading @@ -124,8 +124,7 @@ message SnapshotStatus { // Default value is 32, can be set lower for low mem devices uint32 read_ahead_size = 17; // Enable direct reads on source device bool o_direct = 18; reserved 18; // Blocks size to be verified at once uint64 verify_block_size = 19; Loading Loading @@ -227,6 +226,9 @@ message SnapshotUpdateStatus { // legacy dm-snapshot based snapuserd bool legacy_snapuserd = 11; // Enable direct reads from source device bool o_direct = 12; } // Next: 10 Loading fs_mgr/libsnapshot/include/libsnapshot/snapshot.h +5 −0 Original line number Diff line number Diff line Loading @@ -410,6 +410,7 @@ class SnapshotManager final : public ISnapshotManager { FRIEND_TEST(SnapshotTest, CreateSnapshot); FRIEND_TEST(SnapshotTest, FirstStageMountAfterRollback); FRIEND_TEST(SnapshotTest, FirstStageMountAndMerge); FRIEND_TEST(SnapshotTest, FlagCheck); FRIEND_TEST(SnapshotTest, FlashSuperDuringMerge); FRIEND_TEST(SnapshotTest, FlashSuperDuringUpdate); FRIEND_TEST(SnapshotTest, MapPartialSnapshot); Loading @@ -425,6 +426,7 @@ class SnapshotManager final : public ISnapshotManager { FRIEND_TEST(SnapshotUpdateTest, DataWipeAfterRollback); FRIEND_TEST(SnapshotUpdateTest, DataWipeRollbackInRecovery); FRIEND_TEST(SnapshotUpdateTest, DataWipeWithStaleSnapshots); FRIEND_TEST(SnapshotUpdateTest, FlagCheck); FRIEND_TEST(SnapshotUpdateTest, FullUpdateFlow); FRIEND_TEST(SnapshotUpdateTest, MergeCannotRemoveCow); FRIEND_TEST(SnapshotUpdateTest, MergeInRecovery); Loading Loading @@ -822,6 +824,9 @@ class SnapshotManager final : public ISnapshotManager { // Check if io_uring API's need to be used bool UpdateUsesIouring(LockedFile* lock); // Check if direct reads are enabled for the source image bool UpdateUsesODirect(LockedFile* lock); // Wrapper around libdm, with diagnostics. bool DeleteDeviceIfExists(const std::string& name, const std::chrono::milliseconds& timeout_ms = {}); Loading fs_mgr/libsnapshot/partition_cow_creator.h +3 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,9 @@ struct PartitionCowCreator { uint64_t compression_factor; uint32_t read_ahead_size; // Enable direct reads on source device bool o_direct; // True if multi-threaded compression should be enabled bool enable_threading; Loading fs_mgr/libsnapshot/snapshot.cpp +28 −13 Original line number Diff line number Diff line Loading @@ -1697,6 +1697,9 @@ bool SnapshotManager::PerformInitTransition(InitTransition transition, if (UpdateUsesIouring(lock.get())) { snapuserd_argv->emplace_back("-io_uring"); } if (UpdateUsesODirect(lock.get())) { snapuserd_argv->emplace_back("-o_direct"); } } size_t num_cows = 0; Loading Loading @@ -2114,6 +2117,11 @@ bool SnapshotManager::UpdateUsesIouring(LockedFile* lock) { return update_status.io_uring_enabled(); } bool SnapshotManager::UpdateUsesODirect(LockedFile* lock) { SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock); return update_status.o_direct(); } /* * Please see b/304829384 for more details. * Loading Loading @@ -3016,6 +3024,7 @@ bool SnapshotManager::WriteUpdateState(LockedFile* lock, UpdateState state, status.set_userspace_snapshots(old_status.userspace_snapshots()); status.set_io_uring_enabled(old_status.io_uring_enabled()); status.set_legacy_snapuserd(old_status.legacy_snapuserd()); status.set_o_direct(old_status.o_direct()); } return WriteSnapshotUpdateStatus(lock, status); } Loading Loading @@ -3310,7 +3319,8 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife } auto read_ahead_size = android::base::GetUintProperty<uint>("ro.virtual_ab.read_ahead_size", kReadAheadSizeKb); PartitionCowCreator cow_creator{.target_metadata = target_metadata.get(), PartitionCowCreator cow_creator{ .target_metadata = target_metadata.get(), .target_suffix = target_suffix, .target_partition = nullptr, .current_metadata = current_metadata.get(), Loading @@ -3320,7 +3330,8 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife .using_snapuserd = using_snapuserd, .compression_algorithm = compression_algorithm, .compression_factor = compression_factor, .read_ahead_size = read_ahead_size}; .read_ahead_size = read_ahead_size, }; if (dap_metadata.vabc_feature_set().has_threaded()) { cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded(); Loading Loading @@ -3388,10 +3399,13 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife status.set_io_uring_enabled(true); LOG(INFO) << "io_uring for snapshots enabled"; } if (GetODirectEnabledProperty()) { status.set_o_direct(true); LOG(INFO) << "o_direct for source image enabled"; } if (is_legacy_snapuserd) { LOG(INFO) << "Setting legacy_snapuserd to true"; status.set_legacy_snapuserd(true); LOG(INFO) << "Setting legacy_snapuserd to true"; } } else if (legacy_compression) { LOG(INFO) << "Virtual A/B using legacy snapuserd"; Loading Loading @@ -3827,6 +3841,7 @@ bool SnapshotManager::Dump(std::ostream& os) { ss << "Using snapuserd: " << update_status.using_snapuserd() << std::endl; ss << "Using userspace snapshots: " << update_status.userspace_snapshots() << std::endl; ss << "Using io_uring: " << update_status.io_uring_enabled() << std::endl; ss << "Using o_direct: " << update_status.o_direct() << std::endl; ss << "Using XOR compression: " << GetXorCompressionEnabledProperty() << std::endl; ss << "Current slot: " << device_->GetSlotSuffix() << std::endl; ss << "Boot indicator: booting from " << GetCurrentSlot() << " slot" << std::endl; Loading fs_mgr/libsnapshot/snapshot_test.cpp +35 −0 Original line number Diff line number Diff line Loading @@ -2647,6 +2647,41 @@ TEST_F(SnapshotUpdateTest, BadCowVersion) { ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_)); } TEST_F(SnapshotTest, FlagCheck) { if (!snapuserd_required_) { GTEST_SKIP() << "Skipping snapuserd test"; } ASSERT_TRUE(AcquireLock()); SnapshotUpdateStatus status = sm->ReadSnapshotUpdateStatus(lock_.get()); // Set flags in proto status.set_o_direct(true); status.set_io_uring_enabled(true); status.set_userspace_snapshots(true); sm->WriteSnapshotUpdateStatus(lock_.get(), status); // Ensure a connection to the second-stage daemon, but use the first-stage // code paths thereafter. ASSERT_TRUE(sm->EnsureSnapuserdConnected()); sm->set_use_first_stage_snapuserd(true); auto init = NewManagerForFirstStageMount("_b"); ASSERT_NE(init, nullptr); lock_ = nullptr; std::vector<std::string> snapuserd_argv; ASSERT_TRUE(init->PerformInitTransition(SnapshotManager::InitTransition::SELINUX_DETACH, &snapuserd_argv)); ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-o_direct") != snapuserd_argv.end()); ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-io_uring") != snapuserd_argv.end()); ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-user_snapshot") != snapuserd_argv.end()); } class FlashAfterUpdateTest : public SnapshotUpdateTest, public WithParamInterface<std::tuple<uint32_t, bool>> { public: Loading Loading
fs_mgr/libsnapshot/android/snapshot/snapshot.proto +4 −2 Original line number Diff line number Diff line Loading @@ -124,8 +124,7 @@ message SnapshotStatus { // Default value is 32, can be set lower for low mem devices uint32 read_ahead_size = 17; // Enable direct reads on source device bool o_direct = 18; reserved 18; // Blocks size to be verified at once uint64 verify_block_size = 19; Loading Loading @@ -227,6 +226,9 @@ message SnapshotUpdateStatus { // legacy dm-snapshot based snapuserd bool legacy_snapuserd = 11; // Enable direct reads from source device bool o_direct = 12; } // Next: 10 Loading
fs_mgr/libsnapshot/include/libsnapshot/snapshot.h +5 −0 Original line number Diff line number Diff line Loading @@ -410,6 +410,7 @@ class SnapshotManager final : public ISnapshotManager { FRIEND_TEST(SnapshotTest, CreateSnapshot); FRIEND_TEST(SnapshotTest, FirstStageMountAfterRollback); FRIEND_TEST(SnapshotTest, FirstStageMountAndMerge); FRIEND_TEST(SnapshotTest, FlagCheck); FRIEND_TEST(SnapshotTest, FlashSuperDuringMerge); FRIEND_TEST(SnapshotTest, FlashSuperDuringUpdate); FRIEND_TEST(SnapshotTest, MapPartialSnapshot); Loading @@ -425,6 +426,7 @@ class SnapshotManager final : public ISnapshotManager { FRIEND_TEST(SnapshotUpdateTest, DataWipeAfterRollback); FRIEND_TEST(SnapshotUpdateTest, DataWipeRollbackInRecovery); FRIEND_TEST(SnapshotUpdateTest, DataWipeWithStaleSnapshots); FRIEND_TEST(SnapshotUpdateTest, FlagCheck); FRIEND_TEST(SnapshotUpdateTest, FullUpdateFlow); FRIEND_TEST(SnapshotUpdateTest, MergeCannotRemoveCow); FRIEND_TEST(SnapshotUpdateTest, MergeInRecovery); Loading Loading @@ -822,6 +824,9 @@ class SnapshotManager final : public ISnapshotManager { // Check if io_uring API's need to be used bool UpdateUsesIouring(LockedFile* lock); // Check if direct reads are enabled for the source image bool UpdateUsesODirect(LockedFile* lock); // Wrapper around libdm, with diagnostics. bool DeleteDeviceIfExists(const std::string& name, const std::chrono::milliseconds& timeout_ms = {}); Loading
fs_mgr/libsnapshot/partition_cow_creator.h +3 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,9 @@ struct PartitionCowCreator { uint64_t compression_factor; uint32_t read_ahead_size; // Enable direct reads on source device bool o_direct; // True if multi-threaded compression should be enabled bool enable_threading; Loading
fs_mgr/libsnapshot/snapshot.cpp +28 −13 Original line number Diff line number Diff line Loading @@ -1697,6 +1697,9 @@ bool SnapshotManager::PerformInitTransition(InitTransition transition, if (UpdateUsesIouring(lock.get())) { snapuserd_argv->emplace_back("-io_uring"); } if (UpdateUsesODirect(lock.get())) { snapuserd_argv->emplace_back("-o_direct"); } } size_t num_cows = 0; Loading Loading @@ -2114,6 +2117,11 @@ bool SnapshotManager::UpdateUsesIouring(LockedFile* lock) { return update_status.io_uring_enabled(); } bool SnapshotManager::UpdateUsesODirect(LockedFile* lock) { SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock); return update_status.o_direct(); } /* * Please see b/304829384 for more details. * Loading Loading @@ -3016,6 +3024,7 @@ bool SnapshotManager::WriteUpdateState(LockedFile* lock, UpdateState state, status.set_userspace_snapshots(old_status.userspace_snapshots()); status.set_io_uring_enabled(old_status.io_uring_enabled()); status.set_legacy_snapuserd(old_status.legacy_snapuserd()); status.set_o_direct(old_status.o_direct()); } return WriteSnapshotUpdateStatus(lock, status); } Loading Loading @@ -3310,7 +3319,8 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife } auto read_ahead_size = android::base::GetUintProperty<uint>("ro.virtual_ab.read_ahead_size", kReadAheadSizeKb); PartitionCowCreator cow_creator{.target_metadata = target_metadata.get(), PartitionCowCreator cow_creator{ .target_metadata = target_metadata.get(), .target_suffix = target_suffix, .target_partition = nullptr, .current_metadata = current_metadata.get(), Loading @@ -3320,7 +3330,8 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife .using_snapuserd = using_snapuserd, .compression_algorithm = compression_algorithm, .compression_factor = compression_factor, .read_ahead_size = read_ahead_size}; .read_ahead_size = read_ahead_size, }; if (dap_metadata.vabc_feature_set().has_threaded()) { cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded(); Loading Loading @@ -3388,10 +3399,13 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife status.set_io_uring_enabled(true); LOG(INFO) << "io_uring for snapshots enabled"; } if (GetODirectEnabledProperty()) { status.set_o_direct(true); LOG(INFO) << "o_direct for source image enabled"; } if (is_legacy_snapuserd) { LOG(INFO) << "Setting legacy_snapuserd to true"; status.set_legacy_snapuserd(true); LOG(INFO) << "Setting legacy_snapuserd to true"; } } else if (legacy_compression) { LOG(INFO) << "Virtual A/B using legacy snapuserd"; Loading Loading @@ -3827,6 +3841,7 @@ bool SnapshotManager::Dump(std::ostream& os) { ss << "Using snapuserd: " << update_status.using_snapuserd() << std::endl; ss << "Using userspace snapshots: " << update_status.userspace_snapshots() << std::endl; ss << "Using io_uring: " << update_status.io_uring_enabled() << std::endl; ss << "Using o_direct: " << update_status.o_direct() << std::endl; ss << "Using XOR compression: " << GetXorCompressionEnabledProperty() << std::endl; ss << "Current slot: " << device_->GetSlotSuffix() << std::endl; ss << "Boot indicator: booting from " << GetCurrentSlot() << " slot" << std::endl; Loading
fs_mgr/libsnapshot/snapshot_test.cpp +35 −0 Original line number Diff line number Diff line Loading @@ -2647,6 +2647,41 @@ TEST_F(SnapshotUpdateTest, BadCowVersion) { ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_)); } TEST_F(SnapshotTest, FlagCheck) { if (!snapuserd_required_) { GTEST_SKIP() << "Skipping snapuserd test"; } ASSERT_TRUE(AcquireLock()); SnapshotUpdateStatus status = sm->ReadSnapshotUpdateStatus(lock_.get()); // Set flags in proto status.set_o_direct(true); status.set_io_uring_enabled(true); status.set_userspace_snapshots(true); sm->WriteSnapshotUpdateStatus(lock_.get(), status); // Ensure a connection to the second-stage daemon, but use the first-stage // code paths thereafter. ASSERT_TRUE(sm->EnsureSnapuserdConnected()); sm->set_use_first_stage_snapuserd(true); auto init = NewManagerForFirstStageMount("_b"); ASSERT_NE(init, nullptr); lock_ = nullptr; std::vector<std::string> snapuserd_argv; ASSERT_TRUE(init->PerformInitTransition(SnapshotManager::InitTransition::SELINUX_DETACH, &snapuserd_argv)); ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-o_direct") != snapuserd_argv.end()); ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-io_uring") != snapuserd_argv.end()); ASSERT_TRUE(std::find(snapuserd_argv.begin(), snapuserd_argv.end(), "-user_snapshot") != snapuserd_argv.end()); } class FlashAfterUpdateTest : public SnapshotUpdateTest, public WithParamInterface<std::tuple<uint32_t, bool>> { public: Loading