Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 48c12945 authored by Yifan Hong's avatar Yifan Hong Committed by android-build-merger
Browse files

Merge changes from topic "liblp_virtualab_prepare"

am: f093f217

Change-Id: I26a7222a01679fde82c9987747ebf2a1fba278da
parents 2bb4f40d f093f217
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::New(const LpMetadata& metadata
    }
    if (opener) {
        for (size_t i = 0; i < builder->block_devices_.size(); i++) {
            std::string partition_name = GetBlockDevicePartitionName(builder->block_devices_[i]);
            std::string partition_name = builder->GetBlockDevicePartitionName(i);
            BlockDeviceInfo device_info;
            if (opener->GetInfo(partition_name, &device_info)) {
                builder->UpdateBlockDeviceInfo(i, device_info);
@@ -164,7 +164,7 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::NewForUpdate(const IPartitionO
    // name and system properties.
    // See comments for UpdateMetadataForOtherSuper.
    auto super_device = GetMetadataSuperBlockDevice(*metadata.get());
    if (GetBlockDevicePartitionName(*super_device) != "super" &&
    if (android::fs_mgr::GetBlockDevicePartitionName(*super_device) != "super" &&
        IsRetrofitDynamicPartitionsDevice()) {
        if (!UpdateMetadataForOtherSuper(metadata.get(), source_slot_number, target_slot_number)) {
            return nullptr;
@@ -192,7 +192,8 @@ bool MetadataBuilder::UpdateMetadataForOtherSuper(LpMetadata* metadata, uint32_t
    // Translate block devices.
    auto source_block_devices = std::move(metadata->block_devices);
    for (const auto& source_block_device : source_block_devices) {
        std::string partition_name = GetBlockDevicePartitionName(source_block_device);
        std::string partition_name =
                android::fs_mgr::GetBlockDevicePartitionName(source_block_device);
        std::string slot_suffix = GetPartitionSlotSuffix(partition_name);
        if (slot_suffix.empty() || slot_suffix != source_slot_suffix) {
            // This should never happen. It means that the source metadata
@@ -375,7 +376,7 @@ bool MetadataBuilder::Init(const std::vector<BlockDeviceInfo>& block_devices,
            block_devices_.emplace_back(out);
        }
    }
    if (GetBlockDevicePartitionName(block_devices_[0]) != super_partition) {
    if (GetBlockDevicePartitionName(0) != super_partition) {
        LERROR << "No super partition was specified.";
        return false;
    }
@@ -458,7 +459,7 @@ Partition* MetadataBuilder::FindPartition(const std::string& name) {
    return nullptr;
}

PartitionGroup* MetadataBuilder::FindGroup(const std::string& group_name) {
PartitionGroup* MetadataBuilder::FindGroup(std::string_view group_name) {
    for (const auto& group : groups_) {
        if (group->name() == group_name) {
            return group.get();
@@ -582,8 +583,7 @@ bool MetadataBuilder::GrowPartition(Partition* partition, uint64_t aligned_size)
    CHECK_NE(sectors_per_block, 0);
    CHECK(sectors_needed % sectors_per_block == 0);

    if (IsABDevice() && !IsRetrofitMetadata() &&
        GetPartitionSlotSuffix(partition->name()) == "_b") {
    if (IsABDevice() && ShouldHalveSuper() && GetPartitionSlotSuffix(partition->name()) == "_b") {
        // Allocate "a" partitions top-down and "b" partitions bottom-up, to
        // minimize fragmentation during OTA.
        free_regions = PrioritizeSecondHalfOfSuper(free_regions);
@@ -849,7 +849,7 @@ uint64_t MetadataBuilder::AlignSector(const LpMetadataBlockDevice& block_device,
bool MetadataBuilder::FindBlockDeviceByName(const std::string& partition_name,
                                            uint32_t* index) const {
    for (size_t i = 0; i < block_devices_.size(); i++) {
        if (GetBlockDevicePartitionName(block_devices_[i]) == partition_name) {
        if (GetBlockDevicePartitionName(i) == partition_name) {
            *index = i;
            return true;
        }
@@ -974,7 +974,8 @@ static bool CompareBlockDevices(const LpMetadataBlockDevice& first,
    // Note: we don't compare alignment, since it's a performance thing and
    // won't affect whether old extents continue to work.
    return first.first_logical_sector == second.first_logical_sector && first.size == second.size &&
           GetBlockDevicePartitionName(first) == GetBlockDevicePartitionName(second);
           android::fs_mgr::GetBlockDevicePartitionName(first) ==
                   android::fs_mgr::GetBlockDevicePartitionName(second);
}

bool MetadataBuilder::ImportPartitions(const LpMetadata& metadata,
@@ -1056,8 +1057,9 @@ bool MetadataBuilder::IsRetrofitDynamicPartitionsDevice() {
                                                            false);
}

bool MetadataBuilder::IsRetrofitMetadata() const {
    return GetBlockDevicePartitionName(block_devices_[0]) != LP_METADATA_DEFAULT_PARTITION_NAME;
bool MetadataBuilder::ShouldHalveSuper() const {
    return GetBlockDevicePartitionName(0) == LP_METADATA_DEFAULT_PARTITION_NAME &&
           !IPropertyFetcher::GetInstance()->GetBoolProperty("ro.virtual_ab.enabled", false);
}

bool MetadataBuilder::AddLinearExtent(Partition* partition, const std::string& block_device,
@@ -1083,7 +1085,7 @@ std::vector<Partition*> MetadataBuilder::ListPartitionsInGroup(const std::string
    return partitions;
}

bool MetadataBuilder::ChangePartitionGroup(Partition* partition, const std::string& group_name) {
bool MetadataBuilder::ChangePartitionGroup(Partition* partition, std::string_view group_name) {
    if (!FindGroup(group_name)) {
        LERROR << "Partition cannot change to unknown group: " << group_name;
        return false;
@@ -1121,5 +1123,11 @@ bool MetadataBuilder::ChangeGroupSize(const std::string& group_name, uint64_t ma
    return true;
}

std::string MetadataBuilder::GetBlockDevicePartitionName(uint64_t index) const {
    return index < block_devices_.size()
                   ? android::fs_mgr::GetBlockDevicePartitionName(block_devices_[index])
                   : "";
}

}  // namespace fs_mgr
}  // namespace android
+2 −2
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ static void ResetPropertyFetcher() {
    IPropertyFetcher::OverrideForTesting(std::make_unique<NiceMock<MockPropertyFetcher>>());
}

MockPropertyFetcher* GetMockedInstance() {
MockPropertyFetcher* GetMockedPropertyFetcher() {
    return static_cast<MockPropertyFetcher*>(IPropertyFetcher::GetInstance());
}

@@ -789,7 +789,7 @@ TEST_F(BuilderTest, ABExtents) {

    // A and B slots should be allocated from separate halves of the partition,
    // to mitigate allocating too many extents. (b/120433288)
    ON_CALL(*GetMockedInstance(), GetProperty("ro.boot.slot_suffix", _))
    ON_CALL(*GetMockedPropertyFetcher(), GetProperty("ro.boot.slot_suffix", _))
            .WillByDefault(Return("_a"));

    auto builder = MetadataBuilder::New(device_info, 65536, 2);
+8 −5
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ class Partition final {

  private:
    void ShrinkTo(uint64_t aligned_size);
    void set_group_name(const std::string& group_name) { group_name_ = group_name; }
    void set_group_name(std::string_view group_name) { group_name_ = group_name; }

    std::string name_;
    std::string group_name_;
@@ -227,7 +227,7 @@ class MetadataBuilder {
    Partition* FindPartition(const std::string& name);

    // Find a group by name. If no group is found, nullptr is returned.
    PartitionGroup* FindGroup(const std::string& name);
    PartitionGroup* FindGroup(std::string_view name);

    // Add a predetermined extent to a partition.
    bool AddLinearExtent(Partition* partition, const std::string& block_device,
@@ -252,7 +252,7 @@ class MetadataBuilder {
    // the metadata is exported, to avoid errors during potential group and
    // size shuffling operations. This will return false if the new group does
    // not exist.
    bool ChangePartitionGroup(Partition* partition, const std::string& group_name);
    bool ChangePartitionGroup(Partition* partition, std::string_view group_name);

    // Changes the size of a partition group. Size constraints will not be
    // checked until metadata is exported, to avoid errors during group
@@ -287,6 +287,9 @@ class MetadataBuilder {
    // Return true if a block device is found, else false.
    bool HasBlockDevice(const std::string& partition_name) const;

    // Return the name of the block device at |index|.
    std::string GetBlockDevicePartitionName(uint64_t index) const;

  private:
    MetadataBuilder();
    MetadataBuilder(const MetadataBuilder&) = delete;
@@ -314,8 +317,8 @@ class MetadataBuilder {
    // Return true if the device is retrofitting dynamic partitions.
    static bool IsRetrofitDynamicPartitionsDevice();

    // Return true if "this" metadata represents a metadata on a retrofit device.
    bool IsRetrofitMetadata() const;
    // Return true if _b partitions should be prioritized at the second half of the device.
    bool ShouldHalveSuper() const;

    bool ValidatePartitionGroups() const;

+2 −2
Original line number Diff line number Diff line
@@ -668,7 +668,7 @@ TEST(liblp, AutoSlotSuffixing) {
}

TEST(liblp, UpdateRetrofit) {
    ON_CALL(*GetMockedInstance(), GetBoolProperty("ro.boot.dynamic_partitions_retrofit", _))
    ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.boot.dynamic_partitions_retrofit", _))
            .WillByDefault(Return(true));

    unique_ptr<MetadataBuilder> builder = CreateDefaultBuilder();
@@ -700,7 +700,7 @@ TEST(liblp, UpdateRetrofit) {
}

TEST(liblp, UpdateNonRetrofit) {
    ON_CALL(*GetMockedInstance(), GetBoolProperty("ro.boot.dynamic_partitions_retrofit", _))
    ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.boot.dynamic_partitions_retrofit", _))
            .WillByDefault(Return(false));

    unique_fd fd = CreateFlashedDisk();
+1 −1
Original line number Diff line number Diff line
@@ -44,4 +44,4 @@ class MockPropertyFetcher : public IPropertyFetcher {
}  // namespace fs_mgr
}  // namespace android

android::fs_mgr::MockPropertyFetcher* GetMockedInstance();
android::fs_mgr::MockPropertyFetcher* GetMockedPropertyFetcher();
Loading