From e2883c1ea03e053f693b4ff87d2710eaead0cb2b Mon Sep 17 00:00:00 2001 From: Akilesh Kailash Date: Sat, 3 Apr 2021 06:50:32 +0000 Subject: [PATCH] libsnapshot:snapuserd: Terminate daemon after applying OTA. When all threads are terminated, dm-user handler's are removed from the list. When the last handler is removed, daemon is shutdown gracefully. Bug: 183652708 Test: 1: Apply full OTA and verify daemon is terminated; reapply the OTA to verify daemon is restarted again. 2: vts_libsnapshot_test Signed-off-by: Akilesh Kailash Change-Id: Ibd41223fc0eba884993a533fcc95661f72805db2 --- .../include/libsnapshot/snapuserd_client.h | 2 ++ fs_mgr/libsnapshot/snapshot.cpp | 11 +++++++++++ fs_mgr/libsnapshot/snapshot_test.cpp | 2 ++ 3 files changed, 15 insertions(+) diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapuserd_client.h b/fs_mgr/libsnapshot/include/libsnapshot/snapuserd_client.h index 1dab361c1..280e85730 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/snapuserd_client.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/snapuserd_client.h @@ -69,6 +69,8 @@ class SnapuserdClient { // must ONLY be called if the control device has already been deleted. bool WaitForDeviceDelete(const std::string& control_device); + void CloseConnection() { sockfd_ = {}; } + // Detach snapuserd. This shuts down the listener socket, and will cause // snapuserd to gracefully exit once all handler threads have terminated. // This should only be used on first-stage instances of snapuserd. diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 2c5bf754c..a0a1e4f5f 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -2297,6 +2297,17 @@ bool SnapshotManager::UnmapAllSnapshots(LockedFile* lock) { return false; } } + + // Terminate the daemon and release the snapuserd_client_ object. + // If we need to re-connect with the daemon, EnsureSnapuserdConnected() + // will re-create the object and establish the socket connection. + if (snapuserd_client_) { + LOG(INFO) << "Shutdown snapuserd daemon"; + snapuserd_client_->DetachSnapuserd(); + snapuserd_client_->CloseConnection(); + snapuserd_client_ = nullptr; + } + return true; } diff --git a/fs_mgr/libsnapshot/snapshot_test.cpp b/fs_mgr/libsnapshot/snapshot_test.cpp index 6ed012941..8fae00b75 100644 --- a/fs_mgr/libsnapshot/snapshot_test.cpp +++ b/fs_mgr/libsnapshot/snapshot_test.cpp @@ -2019,6 +2019,8 @@ TEST_F(SnapshotUpdateTest, MapAllSnapshots) { // Read bytes back and verify they match the cache. ASSERT_TRUE(IsPartitionUnchanged("sys_b")); + + ASSERT_TRUE(sm->UnmapAllSnapshots()); } TEST_F(SnapshotUpdateTest, CancelOnTargetSlot) {