Merge "Disable partition verification when device boots on snapshot" into main

This commit is contained in:
Akilesh Kailash 2023-11-15 05:14:50 +00:00 committed by Gerrit Code Review
commit 91161042b7
5 changed files with 17 additions and 13 deletions

View file

@ -51,11 +51,10 @@ SnapshotHandlerManager::SnapshotHandlerManager() {
std::shared_ptr<HandlerThread> SnapshotHandlerManager::AddHandler(
const std::string& misc_name, const std::string& cow_device_path,
const std::string& backing_device, const std::string& base_path_merge,
std::shared_ptr<IBlockServerOpener> opener, int num_worker_threads, bool use_iouring,
bool perform_verification) {
std::shared_ptr<IBlockServerOpener> opener, int num_worker_threads, bool use_iouring) {
auto snapuserd = std::make_shared<SnapshotHandler>(misc_name, cow_device_path, backing_device,
base_path_merge, opener, num_worker_threads,
use_iouring, perform_verification);
use_iouring, perform_verification_);
if (!snapuserd->InitCowDevice()) {
LOG(ERROR) << "Failed to initialize Snapuserd";
return nullptr;

View file

@ -57,8 +57,7 @@ class ISnapshotHandlerManager {
const std::string& backing_device,
const std::string& base_path_merge,
std::shared_ptr<IBlockServerOpener> opener,
int num_worker_threads, bool use_iouring,
bool perform_verification) = 0;
int num_worker_threads, bool use_iouring) = 0;
// Start serving requests on a snapshot handler.
virtual bool StartHandler(const std::string& misc_name) = 0;
@ -84,6 +83,9 @@ class ISnapshotHandlerManager {
// Returns whether all snapshots have verified.
virtual bool GetVerificationStatus() = 0;
// Disable partition verification
virtual void DisableVerification() = 0;
};
class SnapshotHandlerManager final : public ISnapshotHandlerManager {
@ -94,8 +96,7 @@ class SnapshotHandlerManager final : public ISnapshotHandlerManager {
const std::string& backing_device,
const std::string& base_path_merge,
std::shared_ptr<IBlockServerOpener> opener,
int num_worker_threads, bool use_iouring,
bool perform_verification) override;
int num_worker_threads, bool use_iouring) override;
bool StartHandler(const std::string& misc_name) override;
bool DeleteHandler(const std::string& misc_name) override;
bool InitiateMerge(const std::string& misc_name) override;
@ -104,6 +105,7 @@ class SnapshotHandlerManager final : public ISnapshotHandlerManager {
void TerminateMergeThreads() override;
double GetMergePercentage() override;
bool GetVerificationStatus() override;
void DisableVerification() override { perform_verification_ = false; }
private:
bool StartHandler(const std::shared_ptr<HandlerThread>& handler);
@ -128,6 +130,7 @@ class SnapshotHandlerManager final : public ISnapshotHandlerManager {
int num_partitions_merge_complete_ = 0;
std::queue<std::shared_ptr<HandlerThread>> merge_handlers_;
android::base::unique_fd monitor_merge_event_fd_;
bool perform_verification_ = true;
};
} // namespace snapshot

View file

@ -360,16 +360,15 @@ std::shared_ptr<HandlerThread> UserSnapshotServer::AddHandler(const std::string&
num_worker_threads = 1;
}
bool perform_verification = true;
if (android::base::EndsWith(misc_name, "-init") || is_socket_present_) {
perform_verification = false;
if (android::base::EndsWith(misc_name, "-init") || is_socket_present_ ||
(access(kBootSnapshotsWithoutSlotSwitch, F_OK) == 0)) {
handlers_->DisableVerification();
}
auto opener = block_server_factory_->CreateOpener(misc_name);
return handlers_->AddHandler(misc_name, cow_device_path, backing_device, base_path_merge,
opener, num_worker_threads, io_uring_enabled_,
perform_verification);
opener, num_worker_threads, io_uring_enabled_);
}
bool UserSnapshotServer::WaitForSocket() {

View file

@ -40,6 +40,8 @@ namespace snapshot {
static constexpr uint32_t kMaxPacketSize = 512;
static constexpr uint8_t kMaxMergeThreads = 2;
static constexpr char kBootSnapshotsWithoutSlotSwitch[] =
"/metadata/ota/snapshot-boot-without-slot-switch";
class UserSnapshotServer {
private:

View file

@ -627,9 +627,10 @@ void SnapuserdTest::CreateCowDeviceOrderedOps() {
void SnapuserdTest::InitCowDevice() {
auto factory = harness_->GetBlockServerFactory();
auto opener = factory->CreateOpener(system_device_ctrl_name_);
handlers_->DisableVerification();
auto handler =
handlers_->AddHandler(system_device_ctrl_name_, cow_system_->path, base_dev_->GetPath(),
base_dev_->GetPath(), opener, 1, GetParam(), false);
base_dev_->GetPath(), opener, 1, GetParam());
ASSERT_NE(handler, nullptr);
ASSERT_NE(handler->snapuserd(), nullptr);
#ifdef __ANDROID__