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 <akailash@google.com>
Change-Id: Ibd41223fc0eba884993a533fcc95661f72805db2
This commit is contained in:
Akilesh Kailash 2021-04-03 06:50:32 +00:00
parent 99037347d6
commit e2883c1ea0
3 changed files with 15 additions and 0 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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) {