Snap for 11967491 from 6d45f1404e to 24Q3-release

Change-Id: I67c273d49a434c3574b875fa762fd5dc6e699bbc
This commit is contained in:
Android Build Coastguard Worker 2024-06-13 23:25:01 +00:00
commit f9c9ad8198
10 changed files with 102 additions and 25 deletions

View file

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

View file

@ -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);
@ -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);
@ -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 = {});

View file

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

View file

@ -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;
@ -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.
*
@ -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);
}
@ -3310,17 +3319,19 @@ 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(),
.target_suffix = target_suffix,
.target_partition = nullptr,
.current_metadata = current_metadata.get(),
.current_suffix = current_suffix,
.update = nullptr,
.extra_extents = {},
.using_snapuserd = using_snapuserd,
.compression_algorithm = compression_algorithm,
.compression_factor = compression_factor,
.read_ahead_size = read_ahead_size};
PartitionCowCreator cow_creator{
.target_metadata = target_metadata.get(),
.target_suffix = target_suffix,
.target_partition = nullptr,
.current_metadata = current_metadata.get(),
.current_suffix = current_suffix,
.update = nullptr,
.extra_extents = {},
.using_snapuserd = using_snapuserd,
.compression_algorithm = compression_algorithm,
.compression_factor = compression_factor,
.read_ahead_size = read_ahead_size,
};
if (dap_metadata.vabc_feature_set().has_threaded()) {
cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded();
@ -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";
@ -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;

View file

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

View file

@ -29,6 +29,7 @@ DEFINE_bool(socket_handoff, false,
"If true, perform a socket hand-off with an existing snapuserd instance, then exit.");
DEFINE_bool(user_snapshot, false, "If true, user-space snapshots are used");
DEFINE_bool(io_uring, false, "If true, io_uring feature is enabled");
DEFINE_bool(o_direct, false, "If true, enable direct reads on source device");
namespace android {
namespace snapshot {
@ -67,7 +68,6 @@ bool Daemon::StartDaemon(int argc, char** argv) {
if (!user_snapshots) {
user_snapshots = IsUserspaceSnapshotsEnabled();
}
if (user_snapshots) {
LOG(INFO) << "Starting daemon for user-space snapshots.....";
return StartServerForUserspaceSnapshots(arg_start, argc, argv);
@ -109,11 +109,13 @@ bool Daemon::StartServerForUserspaceSnapshots(int arg_start, int argc, char** ar
for (int i = arg_start; i < argc; i++) {
auto parts = android::base::Split(argv[i], ",");
if (parts.size() != 4) {
LOG(ERROR) << "Malformed message, expected four sub-arguments.";
LOG(ERROR) << "Malformed message, expected at least four sub-arguments.";
return false;
}
auto handler = user_server_.AddHandler(parts[0], parts[1], parts[2], parts[3]);
auto handler =
user_server_.AddHandler(parts[0], parts[1], parts[2], parts[3], FLAGS_o_direct);
if (!handler || !user_server_.StartHandler(parts[0])) {
return false;
}

View file

@ -20,6 +20,7 @@
#include <android-base/scopeguard.h>
#include <android-base/strings.h>
#include "android-base/properties.h"
#include "snapuserd_core.h"
namespace android {
@ -104,7 +105,9 @@ bool UpdateVerify::VerifyBlocks(const std::string& partition_name,
}
loff_t file_offset = offset;
const uint64_t read_sz = kBlockSizeVerify;
auto verify_block_size = android::base::GetUintProperty<uint>("ro.virtual_ab.verify_block_size",
kBlockSizeVerify);
const uint64_t read_sz = verify_block_size;
void* addr;
ssize_t page_size = getpagesize();
@ -130,7 +133,7 @@ bool UpdateVerify::VerifyBlocks(const std::string& partition_name,
}
bytes_read += to_read;
file_offset += (skip_blocks * kBlockSizeVerify);
file_offset += (skip_blocks * verify_block_size);
if (file_offset >= dev_sz) {
break;
}
@ -184,7 +187,9 @@ bool UpdateVerify::VerifyPartition(const std::string& partition_name,
* latency.
*/
int num_threads = kMinThreadsToVerify;
if (dev_sz > kThresholdSize) {
auto verify_threshold_size = android::base::GetUintProperty<uint>(
"ro.virtual_ab.verify_threshold_size", kThresholdSize);
if (dev_sz > verify_threshold_size) {
num_threads = kMaxThreadsToVerify;
}
@ -192,11 +197,13 @@ bool UpdateVerify::VerifyPartition(const std::string& partition_name,
off_t start_offset = 0;
const int skip_blocks = num_threads;
auto verify_block_size =
android::base::GetUintProperty("ro.virtual_ab.verify_block_size", kBlockSizeVerify);
while (num_threads) {
threads.emplace_back(std::async(std::launch::async, &UpdateVerify::VerifyBlocks, this,
partition_name, dm_block_device, start_offset, skip_blocks,
dev_sz));
start_offset += kBlockSizeVerify;
start_offset += verify_block_size;
num_threads -= 1;
if (start_offset >= dev_sz) {
break;

View file

@ -199,7 +199,7 @@ bool WriteStringToFileAtomic(const std::string& content, const std::string& path
}
std::ostream& operator<<(std::ostream& os, const Now&) {
struct tm now {};
struct tm now{};
time_t t = time(nullptr);
localtime_r(&t, &now);
return os << std::put_time(&now, "%Y%m%d-%H%M%S");
@ -272,6 +272,11 @@ bool GetXorCompressionEnabledProperty() {
return fetcher->GetBoolProperty("ro.virtual_ab.compression.xor.enabled", false);
}
bool GetODirectEnabledProperty() {
auto fetcher = IPropertyFetcher::GetInstance();
return fetcher->GetBoolProperty("ro.virtual_ab.o_direct.enabled", false);
}
std::string GetOtherPartitionName(const std::string& name) {
auto suffix = android::fs_mgr::GetPartitionSlotSuffix(name);
CHECK(suffix == "_a" || suffix == "_b");

View file

@ -133,6 +133,7 @@ bool GetLegacyCompressionEnabledProperty();
bool GetUserspaceSnapshotsEnabledProperty();
bool GetIouringEnabledProperty();
bool GetXorCompressionEnabledProperty();
bool GetODirectEnabledProperty();
bool CanUseUserspaceSnapshots();
bool IsDmSnapshotTestingEnabled();

View file

@ -245,8 +245,10 @@ extern "C" int modprobe_main(int argc, char** argv) {
}
free(kernel_dirs);
// Allow modules to be directly inside /lib/modules
mod_dirs.emplace_back(LIB_MODULES_PREFIX);
if (mod_dirs.empty() || getpagesize() == 4096) {
// Allow modules to be directly inside /lib/modules
mod_dirs.emplace_back(LIB_MODULES_PREFIX);
}
}
LOG(DEBUG) << "mode is " << mode;